function out=conn_importspm(spmfiles) % Imports experiment info from SPM.mat files % global CONN_x; if nargin>0, if ~iscell(spmfiles),spmfiles=cellstr(spmfiles);end nsubjects=length(spmfiles); if nsubjects~=CONN_x.Setup.nsubjects, CONN_x.Setup.nsubjects=conn_merge(CONN_x.Setup.nsubjects,nsubjects); end for nsub=1:nsubjects, filename=fliplr(deblank(fliplr(deblank(spmfiles{nsub})))); CONN_x.Setup.spm{nsub}=conn_file(filename); end end %CONN_x.Setup.nsessions=zeros(1,CONN_x.Setup.nsubjects); changed=0;err=0; for nsub=1:CONN_x.Setup.nsubjects, if ~isempty(CONN_x.Setup.spm{nsub}{1}), %try, spmfile=load(CONN_x.Setup.spm{nsub}{1}); if isfield(spmfile.SPM,'xBF')&&isfield(spmfile.SPM.xBF,'UNITS'), units=spmfile.SPM.xBF.UNITS; if strcmp(units,'scans'), units=1; elseif strcmp(units,'secs'), units=2; else, disp(['warning: importing from ',CONN_x.Setup.spm{nsub}{1},': invalid SPM.xBF.UNITS value (assuming scans)']); err=err+1; end else, disp(['warning: importing from ',CONN_x.Setup.spm{nsub}{1},': SPM.xBF.UNITS not found (assuming scans)']); units=1; err=err+1; end if isfield(spmfile.SPM,'xY')&&isfield(spmfile.SPM.xY,'RT'), CONN_x.Setup.RT=spmfile.SPM.xY.RT; else, disp(['warning: importing from ',CONN_x.Setup.spm{nsub}{1},': SPM.xY.RT not found (leaving unchanged)']); err=err+1; end if ~isfield(spmfile.SPM,'nscan'), disp(['warning: importing from ',CONN_x.Setup.spm{nsub}{1},': SPM.nscan not found (stopped importing for this subject)']); err=err+1; else, nsess=length(spmfile.SPM.nscan); CONN_x.Setup.nsessions(nsub)=nsess; for nses=1:nsess, idx=spmfile.SPM.Sess(nses).row; filename=fliplr(deblank(fliplr(deblank(spmfile.SPM.xY.P(idx,:))))); switch(filesep),case '\',idx=find(filename=='/');case '/',idx=find(filename=='\');end; filename(idx)=filesep; n=0; while n