Home > fmri > utils > post_process_corrmat.m

post_process_corrmat

PURPOSE ^

plots & returns the design matrix intercorrelation for an SPM analysis

SYNOPSIS ^

function [cmat, X] = post_process_corrmat(spm_fname,opt)

DESCRIPTION ^

 plots & returns the design matrix intercorrelation for an SPM analysis
 
   [cmat X] = post_process_corrmat(spm_fname)
 
 REQUIRES
   opt.figh - handle of figure to print the correlation matrix to
   opt.names - regressor names (from SPM.xX.name) that you want to
       correlate. If not provided, all regressors in the design matrix
       will be correlated
   opt.plot_corr_txt - text to be printed on figure
   opt.printfig - (1) print the figure, return values, (0) return values
   opt.title
   opt.figstub
   opt.append_str
 
 05/19/06 Petr Janata - modified from a 2004 version of the script.  Added
 support for SPM5 structure of the SPM.mat file.
 2010.02.16 FB - added opt.names, header documentation

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [cmat, X] = post_process_corrmat(spm_fname,opt)
0002 % plots & returns the design matrix intercorrelation for an SPM analysis
0003 %
0004 %   [cmat X] = post_process_corrmat(spm_fname)
0005 %
0006 % REQUIRES
0007 %   opt.figh - handle of figure to print the correlation matrix to
0008 %   opt.names - regressor names (from SPM.xX.name) that you want to
0009 %       correlate. If not provided, all regressors in the design matrix
0010 %       will be correlated
0011 %   opt.plot_corr_txt - text to be printed on figure
0012 %   opt.printfig - (1) print the figure, return values, (0) return values
0013 %   opt.title
0014 %   opt.figstub
0015 %   opt.append_str
0016 %
0017 % 05/19/06 Petr Janata - modified from a 2004 version of the script.  Added
0018 % support for SPM5 structure of the SPM.mat file.
0019 % 2010.02.16 FB - added opt.names, header documentation
0020 
0021 if nargin < 2
0022   opt = struct();
0023 end
0024 
0025 load new_seismic  % colormap
0026 
0027 data = load(spm_fname);
0028 if isfield(data,'SPM')
0029   xX = data.SPM.xX;
0030   Xnames = xX.name;
0031   Sess = data.SPM.Sess;
0032 else
0033   xX = data.xX;
0034   Xnames = xX.Xnames;
0035   Sess = data.Sess;
0036 end
0037 
0038 % Initialize a figure
0039 if isfield(opt,'figh')
0040   figure(opt.figh), clf
0041 else
0042   figure
0043   opt.figh = gcf;
0044 end
0045 
0046 nruns = length(Sess);
0047 for irun = 1:nruns
0048   % Get the columns corresponding to this run
0049   cc = Sess(irun).col;
0050   cr = Sess(irun).row;
0051 
0052   % only plot a subset of correlations?
0053   if isfield(opt,'names')
0054     cc = find(ismember(Xnames,opt.names));
0055   end
0056 
0057   % Get the data corresponding to this run
0058   X = xX.X(cr,cc);
0059 
0060   % Get the names corresponding to this run
0061   cnames = Xnames(cc);
0062   
0063   % If there is a constant column, remove it
0064   rem_col = find(sum(X) == size(X,1));
0065   if ~isempty(rem_col)
0066     X(:,rem_col) = [];
0067     cnames{rem_col} = [];
0068   end
0069   
0070   cmat = corrcoef(X);  % calculate the correlation matrix
0071 
0072   % Initialize a subplot
0073   subplot(nruns,1,irun)
0074   
0075   % Plot the matrix
0076   imagesc(cmat,[-1 1]), axis square
0077 
0078   colormap(new_seismic)
0079   colorbar
0080 
0081   set(gca,'ytick',1:size(cmat,2))
0082   set(gca,'yticklabel',cnames)
0083 
0084   if isfield(opt,'plot_corr_txt') && opt.plot_corr_txt
0085     for ir = 1:size(cmat,1)
0086       for ic = 1:size(cmat,2)
0087     text(ic,ir,sprintf('%1.2f', cmat(ir,ic)),'horizontalalign','center')
0088       end
0089     end
0090   end
0091 
0092   set(gca,'xtick',[])
0093   set(gca,'ticklen',[0 0])
0094 
0095   if nruns == 1
0096     for ic = 1:size(cmat,2)
0097       text(ic,size(cmat,1)+0.5,strrep(cnames{ic},'_','\_'),'rotation',-90,'horizontalalign','left')
0098     end
0099   end
0100 
0101   if isfield(opt,'title')
0102     if irun == 1
0103       title_str = sprintf('%s, Run %d', opt.title, irun);
0104     else
0105       title_str = sprintf('Run %d', irun);
0106     end
0107     title(title_str,'fontsize',14)
0108   end
0109 end % for irun
0110 
0111   
0112 try 
0113   if opt.printfig
0114     print(sprintf('%s.ps',opt.figstub),'-dpsc', opt.append_str)
0115     
0116     %    unix_str = sprintf('ps2pdf %s.ps %s.pdf', opt.figstub, opt.figstub);
0117     %    unix(unix_str);
0118     %    unix(sprintf('rm %s.ps >> /dev/null', opt.figstub));
0119   end
0120 catch
0121 end
0122 
0123 
0124 if nargout > 1
0125     X = xX.X;
0126 end

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003