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

📄 fmri_plot_corr.m

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

   st_files = getappdata(gcf,'STFiles');
   conditions = getappdata(gcf,'Conditions');

   h = findobj(gcf,'Tag','PlotButton');
   if strcmp(lower(get(h,'Enable')),'off'),  return; end;

   h = findobj(gcf,'Tag','STDatamatPopup');
   popup_string = get(h,'String');
   selected_idx = get(h,'Value');
   selected_data = popup_string{selected_idx};

   %  load the datamat if not loaded yet
   %
   last_datamat = getappdata(gcf,'PlottedDatamat');
   if strcmp(last_datamat,selected_data) == 0 

       set(findobj(gcf,'Tag','MessageLine'),'String','Loading data ... ');

       [st_datamat, st_coords, st_win_size, st_evt_list] = ...
						load_plotted_datamat;
       setappdata(gcf,'PlottedDatamat',selected_data);
       setappdata(gcf,'STDatamat',st_datamat);
       setappdata(gcf,'STCoords',st_coords);
       setappdata(gcf,'STWinSize',st_win_size);
       setappdata(gcf,'STEvtList',st_evt_list);

       set(findobj(gcf,'Tag','MessageLine'),'String','');
   else
       st_win_size = getappdata(gcf,'STWinSize');
       st_evt_list = getappdata(gcf,'STEvtList');
       st_coords = getappdata(gcf,'STCoords');
   end;

   num_pts_plotted = getappdata(gcf,'NumPtsPlotted');
   if isempty(num_pts_plotted)
      num_pts_plotted = st_win_size;
      setappdata(gcf,'NumPtsPlotted',num_pts_plotted);
   elseif (num_pts_plotted > st_win_size),
      num_pts_plotted = st_win_size;
   end;

   
   %  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);
       return;
   end;

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


   st_datamat = getappdata(gcf,'STDatamat'); 

   [nr,nc] = size(st_datamat);
   cols = nc / st_win_size;
   st_data = reshape(st_datamat,[nr,st_win_size,cols]);
   st_data = squeeze(st_data(:,[1:num_pts_plotted],coord_idx));
   
   h = findobj(gcf,'Tag','NormalizePlots');
   normalize_flg = get(h,'UserData');
   if (normalize_flg == 1),
      max_st_data = max(st_data,[],2);
      min_st_data = min(st_data,[],2);

      max_mtx = max_st_data(:,ones(1,num_pts_plotted));
      min_mtx = min_st_data(:,ones(1,num_pts_plotted));
      scale_factor = max_mtx - min_mtx;
      st_data = (st_data - min_mtx) ./ scale_factor;
   end;


   selected_condition = getappdata(gcf,'SelectedCondition');
   num_conditions = length(selected_condition);
   condition = cell(1,num_conditions);  

   max_num_stim = 0;
   for i=1:num_conditions,
      condition{i}.st_row_idx  = find(st_evt_list == i);
      condition{i}.num_stim = length(condition{i}.st_row_idx);
      condition{i}.name = conditions{i};
      if (max_num_stim < condition{i}.num_stim)
          max_num_stim = condition{i}.num_stim;
      end;
   end;


   % generate the plots
   %
   plot_cond_idx = find(selected_condition == 1);

   plot_dims = getappdata(gcf,'PlotDims');
   if isempty(plot_dims) 
       if (num_conditions < 5)
         num_rows = num_conditions;
       else
         num_rows = 5;
       end;
       if (max_num_stim < 4),
         num_cols = max_num_stim;
       else
         num_cols = 4;
       end;
       plot_dims = [num_rows num_cols];
   end;

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

   fmri_plot_cond_stim_ui('STARTUP', st_data, condition,  ...
           	                    axes_margin, plot_dims, plot_cond_idx);

   setappdata(gcf,'PLS_PLOT_COND_STIM_ACTIVE',1);
   set(findobj(gcf,'Tag','PlotMenu'),'Enable','off');
   set(findobj(gcf,'Tag','OptionMenu'),'Enable','on');
   set(findobj(gcf,'Tag','DataMenu'),'Enable','on');

   return;


%--------------------------------------------------------------------------
%
function  save_response_fn()

   st_win_size = getappdata(gcf,'STWinSize');
   st_evt_list = getappdata(gcf,'STEvtList');
   st_coords = getappdata(gcf,'STCoords');
   xyz = getappdata(gcf,'XYZ');
   lag = getappdata(gcf,'lag');

   %  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);
       return;
   end;

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

   %  get all the file names 
   %
%   selected_files = get_selected_filename(1);

   %  extract the time course data of the selected voxel
   %
%   st_datamat = getappdata(gcf,'STDatamat'); 

%   [nr,nc] = size(st_datamat);
%   cols = nc / st_win_size;
%   st_data = reshape(st_datamat,[nr,st_win_size,cols]);
%   st_data = squeeze(st_data(:,[1:st_win_size],coord_idx));

   st_data = getappdata(gcf,'ST_data');

%   st_data = st_data(:,lag+1);

%   fn = getappdata(gcf,'STFiles');
%   fn = fn{1}.name;

   [filename, pathname] = ...
	uiputfile('*_fMRI_datamatcorr_plot.mat','Save Datamat Correlation Response Function');

   if ischar(filename) & isempty(findstr(lower(filename),'_fmri_datamatcorr_plot'))
      [tmp filename] = fileparts(filename);
      filename = [filename, '_fMRI_datamatcorr_plot.mat'];
   end

   if isequal(filename,0)
	return;
   end;
   rf_plot_file = fullfile(pathname,filename);

   xyz_str = 'xyz';
 
   sa = getappdata(gcf, 'sa');

   if ~isempty(sa) & sa == 1
      yzx = xyz;
      xyz_str = 'yzx';
   elseif ~isempty(sa) & sa == 0
      xzy = xyz;
      xyz_str = 'xzy';
   end

   try
     save (rf_plot_file, 'st_data', xyz_str, 'lag' );
   catch
     msg = sprintf('Cannot save the response function data to %s',rf_plot_file);
     set(findobj(gcf,'Tag','MessageLine'),'String',['ERROR: ', msg]);
     status = 0;
     return;
   end;

   return;                                      % save_response_fn


%--------------------------------------------------------------------------
%
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', 'st_win_size', 'cond_name', ...
	'subj_name', 'bscan');
   warning on;

   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

   setappdata(gcf,'datamatcorrs_lst',datamatcorrs_lst);
   setappdata(gcf,'STCoords',st_coords);
   setappdata(gcf,'STWinSize',st_win_size);
   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;                                       % get_st_datamat_filename


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

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

   grp_idx = get(popup_h,'value');

   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;

   return;


%--------------------------------------------------------------------------
%
function  plot_datamatcorrs

   emp_st_data = 0;

   %  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);
%       return;
       emp_st_data = 1;
   end;

   conditions = getappdata(gcf,'Conditions');

   st_coords = getappdata(gcf,'STCoords');
   st_win_size = getappdata(gcf,'STWinSize');

   num_pts_plotted = getappdata(gcf,'NumPtsPlotted');
   if isempty(num_pts_plotted)
      num_pts_plotted = st_win_size;
      setappdata(gcf,'NumPtsPlotted',num_pts_plotted);
   elseif (num_pts_plotted > st_win_size),
      num_pts_plotted = st_win_size;
   end;

   coord_idx = find(st_coords == cur_coord);

   if isempty(coord_idx)
       msg = 'ERROR: The selected point is outside the brain region.';
       set(findobj(gcf,'Tag','MessageLine'),'String',msg);
%       return;
       emp_st_data = 1;
   end;

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

   st_evt = ones(1,num_behav);
   st_evt_list = [];
   for i=1:num_cond
      st_evt_list = [st_evt_list, st_evt.*i];
   end

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

   [nr,nc] = size(st_data);
   cols = nc / st_win_size;
   st_data = reshape(st_data,[nr,st_win_size,cols]);
   st_data = squeeze(st_data(:,[1:num_pts_plotted],coord_idx));
   
   h = findobj(gcf,'Tag','NormalizePlots');
   normalize_flg = get(h,'UserData');
   if (normalize_flg == 1),
      max_st_data = max(st_data,[],2);
      min_st_data = min(st_data,[],2);

      max_mtx = max_st_data(:,ones(1,num_pts_plotted));
      min_mtx = min_st_data(:,ones(1,num_pts_plotted));
      scale_factor = max_mtx - min_mtx;
      st_data = (st_data - min_mtx) ./ scale_factor;
   end;

   if emp_st_data
      st_data = [];
   end

   selected_condition = getappdata(gcf,'SelectedCondition');
   num_conditions = length(selected_condition);
   condition = cell(1,num_conditions);  

   max_num_stim = 0;
   for i=1:num_cond,
      condition{i}.st_row_idx  = find(st_evt_list == i);
      condition{i}.num_stim = length(condition{i}.st_row_idx);
      condition{i}.name = conditions{i};
      if (max_num_stim < condition{i}.num_stim)
          max_num_stim = condition{i}.num_stim;
      end;
   end;


   % generate the plots
   %
   plot_cond_idx = find(selected_condition == 1);

   plot_dims = getappdata(gcf,'PlotDims');
   if isempty(plot_dims) 
       if (num_conditions < 5)
         num_rows = num_conditions;
       else
         num_rows = 5;
       end;
       if (max_num_stim < 4),
         num_cols = max_num_stim;
       else
         num_cols = 4;
       end;
       plot_dims = [num_rows num_cols];
   end;

   setappdata(gcf,'ShowAverage',0);

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

   fmri_plot_cond_stim_ui('STARTUP', st_data, condition,  ...
           	                    axes_margin, plot_dims, plot_cond_idx);

   setappdata(gcf,'PLS_PLOT_COND_STIM_ACTIVE',1);
   set(findobj(gcf,'Tag','PlotMenu'),'Enable','off');
   set(findobj(gcf,'Tag','OptionMenu'),'Enable','on');
   set(findobj(gcf,'Tag','DataMenu'),'Enable','on');

   return;

⌨️ 快捷键说明

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