⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bfm_plot_rf.m

📁 绝对经典,老外制作的功能强大的matlab实现PLS_TOOBOX
💻 M
📖 第 1 页 / 共 4 页
字号:
%
function  plot_datamatcorrs

   axes_margin = [.37 .05 .15 .1];

   % set up axes, and the values of 'AxesMargin', 'AxesHlds' and 'AxesPos'
   %
   setappdata(gcf,'AxesMargin',axes_margin);
   set_cond_axes(1,1,axes_margin);     % set up axes

   %  extract the currect ploting data
   %
   cur_coord = getappdata(gcf,'Coord');
   if isempty(cur_coord)
       msg = 'ERROR: No point has been seleted to plot.';
       set(findobj(gcf,'Tag','MessageLine'),'String',msg);
       set(gca,'visible','off');
       return;
   end;

   %  find out the coord_idx
   %
   st_coords = getappdata(gcf,'STCoords');
   common_coords = getappdata(gcf,'common_coords');

   coord_idx = find(common_coords == cur_coord);
   if isempty(coord_idx)
       msg = 'ERROR: The selected point is outside the brain region.';
       set(findobj(gcf,'Tag','MessageLine'),'String',msg);
       set(gca,'visible','off');
       return;
   end;
   coord_idx = find(st_coords == cur_coord);

   num_cond = getappdata(gcf,'num_cond');
   st_data = getappdata(gcf,'datamatcorrs');
   num_behav = getappdata(gcf,'num_behav');

   % generate the plots
   %
   cond_idx = [1:num_cond];

   setappdata(gcf,'ST_data',st_data);
   setappdata(gcf,'PlotCondIdx',cond_idx);

   if isempty(getappdata(gcf,'CombinePlots'))
      setappdata(gcf,'CombinePlots',0);
   end;

   if isempty(getappdata(gcf,'ShowAverage'))
      setappdata(gcf,'ShowAverage',0);
   end;

   behavname = getappdata(gcf,'behavname');

   for k = cond_idx			% cond
      for n = 1:num_behav		% behav
         j = n+(k-1)*num_behav;		% row number in datamat
         intensity(j) = st_data(j, coord_idx);
      end
   end

   mask = [];

   for i=1:num_behav
      for j=1:num_cond
         mask = [mask (j-1)*num_behav+i];
      end
   end

   cla;grid on;box on;hold on;

   load('rri_color_code');

   for i=1:num_behav
      for j=1:num_cond
         k = (i-1)*num_cond + j;
         bar_hdl = bar(k, intensity(mask(k)));
         set(bar_hdl,'facecolor',color_code(j,:));
      end
   end

   min_x = 0.5;		max_x = num_cond * num_behav + 0.5;
   min_y =-1;		max_y = 1;
   margin_x = abs((max_x - min_x) / 20);
   margin_y = abs((max_y - min_y) / 20);

   axis([min_x-margin_x,max_x+margin_x,min_y-margin_y,max_y+margin_y]);

   set(gca,'xtick',[1:num_cond:num_cond*num_behav]);

   cond_name = getappdata(gcf,'cond_name');

   set(gca,'xticklabel',behavname);

   ylabel('Correlation');

   xyz = getappdata(gcf,'XYZ');
   title(['Datamat correlations at voxel:  [',num2str(xyz),']']);

   hold off;

   l_hdl = [];

   if ~isempty(cond_name),

      % remove the old legend to avoid the bug in the MATLAB5
      old_legend = getappdata(gcf,'LegendHdl');
      if ~isempty(old_legend),
        try
          delete(old_legend{1});
        catch
        end;
      end;

      % create a new legend, and save the handles
      [l_hdl, o_hdl] = legend(cond_name, 0);
      legend_txt(o_hdl);
      set(l_hdl,'color',[0.9 1 0.9]);
      setappdata(gcf,'LegendHdl',[{l_hdl} {o_hdl}]);

   else

      setappdata(gcf,'LegendHdl',[]);

   end;

   set(findobj(gcf,'Tag','DataMenuBehav'),'visible','on');

   return;						% plot_datamatcorrs


%--------------------------------------------------------------------------
%
function load_datamatcorrs(PLSresultFile)

   old_pointer = get(gcf,'Pointer');
   set(gcf,'Pointer','watch');

   warning off;
   load(PLSresultFile, 'datamatcorrs_lst', 'num_subj_lst', 'behavname', ...
	'num_conditions', 'st_coords', 'cond_name', 'subj_name', 'bscan');
   warning on;

   common_coords = st_coords;

   if ~exist('datamatcorrs_lst', 'var')
uiwait(msgbox('Need use new version to run PLS analysis again in order to get the correlation file'));
      return;
   end


     cond_selection = getappdata(gcf,'cond_selection');

     if exist('cond_selection','var') & ~isempty(cond_selection)
         num_conditions = sum(cond_selection);
     end

     if exist('bscan','var') & ~isempty(bscan)
         cond_name = cond_name(bscan);
     end


    %  apply origin_pattern here
    %
    mainfig = getappdata(gcf,'CallBackFig');
    origin_pattern = getappdata(mainfig,'origin_pattern');

    if ~isempty(origin_pattern)
       dims = getappdata(mainfig,'STDims');
       new_coord = zeros(dims);
       new_coord(st_coords) = 1;
       new_coord = find(new_coord(origin_pattern));

       for i=1:length(datamatcorrs_lst)
          datamat = datamatcorrs_lst{i};
          datamat = rri_xy_orient_data(datamat',st_coords,new_coord,...
					dims,origin_pattern);
          datamatcorrs_lst{i} = datamat';
       end

       st_coords = new_coord;
       common_coords = new_coord;
    end



   setappdata(gcf,'datamatcorrs_lst',datamatcorrs_lst);
   setappdata(gcf,'STCoords',st_coords);
   setappdata(gcf,'common_coords',common_coords);
   setappdata(gcf,'num_subj_lst',num_subj_lst);
   setappdata(gcf,'num_cond',num_conditions);
   setappdata(gcf,'behavname',behavname);
   setappdata(gcf,'subj_name',subj_name);
   setappdata(gcf,'cond_name',cond_name);
   setappdata(gcf,'num_behav',length(behavname));

   setappdata(gcf,'datamatcorrs', datamatcorrs_lst{1});
   setappdata(gcf,'num_behav_subj',num_subj_lst(1));

   num_group = length(num_subj_lst);
   popup_list = cell(1,num_group);
   for i=1:num_group
      popup_list{i} = sprintf('[ Group #%d ]',i);
   end;

   popup_h = findobj(gcf,'Tag','STDatamatPopup');
   set(popup_h,'String',popup_list, ...
               'HorizontalAlignment', 'left','Value',1);

   set(gcf,'Pointer',old_pointer);

   return;


%--------------------------------------------------------------------------
%
function change_group

   popup_h = findobj(gcf,'Tag','STDatamatPopup');

   grp_idx = get(popup_h,'value');

   if ~getappdata(gcf,'actualHRF')	%getappdata(gcf,'isbehav')

      datamatcorrs_lst = getappdata(gcf,'datamatcorrs_lst');
      num_subj_lst = getappdata(gcf,'num_subj_lst');

      setappdata(gcf,'datamatcorrs', datamatcorrs_lst{grp_idx});
      setappdata(gcf,'num_behav_subj',num_subj_lst(grp_idx));

      plot_datamatcorrs;

   else

      datamat_lst = getappdata(gcf,'datamat_lst');
      subj_name_lst = getappdata(gcf,'subj_name_lst');
      num_subj_lst = getappdata(gcf,'num_subj_lst');

      setappdata(gcf,'STDatamat', datamat_lst{grp_idx});
      setappdata(gcf,'subj_name', subj_name_lst{grp_idx});
      setappdata(gcf,'num_subj', num_subj_lst(grp_idx));

      plot_response_fn;

   end

   return;


%--------------------------------------------------------------------------
%
function load_voxel_intensity(PLSresultFile)

   cond_selection = getappdata(gcf,'cond_selection');

   old_pointer = get(gcf,'Pointer');
   set(gcf,'Pointer','watch');

   warning off;
%   load(PLSresultFile, 'datamatcorrs_lst', 'num_subj_lst', 'behavname', ...
%	'num_conditions', 'st_coords', 'cond_name', 'subj_name');
   load(PLSresultFile, 'SessionProfiles', 'subj_group', 'num_conditions', ...
	'st_coords', 'cond_name');
   warning on;

   rri_changepath('bfmriresult');

   common_coords = st_coords;

   if ~exist('subj_group', 'var')
uiwait(msgbox('Need use new version to run PLS analysis again in order to get the correlation file'));
      return;
   end

   num_group = length(SessionProfiles);
   DatamatFile = cell(size(SessionProfiles));
   datamat_lst = {};
   subj_name_lst = {};
   num_subj_lst = [];

   for i = 1:num_group

      grp_datamat = [];
      subj_name = {};
      num_subj = length(SessionProfiles{i});	% session group (actually subj.)

      for n = 1:num_subj

         load(SessionProfiles{i}{n});
         rri_changepath('bfmrisession');

         num_conditions = session_info.num_conditions;

%         if findstr('BfMRIsession.mat', SessionProfiles{i}{n})
%            DatamatFile{i}{n} = sprintf('%s_BfMRIdatamat.mat', session_info.datamat_prefix);
%         else
%            DatamatFile{i}{n} = sprintf('%s_fMRIdatamat.mat', session_info.datamat_prefix);
%         end

         if isempty(cond_selection)
            cond_selection = ones(1, num_conditions);
         else
            num_conditions = sum(cond_selection);
         end

%         DatamatFile{i}{n} = strrep(SessionProfiles{i}{n}, 'session', 'datamat');
         DatamatFile{i}{n} = fullfile(session_info.pls_data_path, ...
		[session_info.datamat_prefix, '_BfMRIdatamat.mat']);

         load(DatamatFile{i}{n});

         [tmp, idx] = intersect(st_coords, common_coords);
         st_datamat = st_datamat(:,idx);

%         task_idx = cell(1, num_conditions);
         mean_datamat = zeros(num_conditions, size(st_datamat,2));

         %  compute the mean data of each condition for this session group 
         %
         cnt = 1;

         for k = find(cond_selection)
            mean_datamat(cnt,:) = mean(st_datamat(find(st_evt_list == k),:), 1);
            cnt = cnt + 1;
         end

         grp_datamat = [grp_datamat; mean_datamat];
         subj_name = [subj_name, {['Subj', num2str(n)]}];

      end

      %  convert to 'subj in cond' form
      %
      mask = [1 : (num_conditions * num_subj)];
      mask = reshape(mask, [num_conditions, num_subj]);
      mask = mask';
      mask = mask(:);

      num_subj_lst = [num_subj_lst num_subj];



       coords = st_coords(idx);

       %  apply origin_pattern here
       %
       mainfig = getappdata(gcf,'CallBackFig');
       origin_pattern = getappdata(mainfig,'origin_pattern');

       if ~isempty(origin_pattern)
          dims = getappdata(mainfig,'STDims');
          new_coord = zeros(dims);
          new_coord(coords) = 1;
          new_coord = find(new_coord(origin_pattern));

          grp_datamat = ...
		rri_xy_orient_data(grp_datamat',coords,new_coord, ...
			dims,origin_pattern);
          grp_datamat = grp_datamat';

       end



      datamat_lst{i} = grp_datamat(mask, :);
      subj_name_lst{i} = subj_name;

   end



   if ~isempty(origin_pattern)
      st_coords = change_coords(st_coords, dims, origin_pattern);
      common_coords = change_coords(common_coords, dims, origin_pattern);
   end



   setappdata(gcf,'DatamatFile',DatamatFile);
   setappdata(gcf,'datamat_lst',datamat_lst);
   setappdata(gcf,'STCoords',st_coords);
   setappdata(gcf,'num_subj_lst',num_subj_lst);
   setappdata(gcf,'subj_name_lst',subj_name_lst);
   setappdata(gcf,'num_cond',num_conditions);
   setappdata(gcf,'cond_name',cond_name);

   setappdata(gcf,'STDatamat', datamat_lst{1});
   setappdata(gcf,'subj_name',subj_name_lst{1});
   setappdata(gcf,'num_subj',num_subj_lst(1));

   setappdata(gcf,'common_coords',common_coords);

   popup_list = cell(1,num_group);
   for i=1:num_group
      popup_list{i} = sprintf('[ Group #%d ]',i);
   end;

   popup_h = findobj(gcf,'Tag','STDatamatPopup');
   set(popup_h,'String',popup_list, ...
               'HorizontalAlignment', 'left','Value',1);

   set(gcf,'Pointer',old_pointer);

   return;


%--------------------------------------------------------------------------
%
function new_coords = change_coords(old_coords, dims, pattern)

   img = zeros(dims);
   img(old_coords) = 1;
   img = img(pattern);
   new_coords = find(img);   

   return;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -