help > RE: RE: Encountered an issue with CONN data import
2 hours ago | Han Lai
RE: RE: Encountered an issue with CONN data import

Hi Alfonso,


Thank you for your reply.


Regarding the session merging, the details can be found in my first-level analysis code. I've attached the relevant files (taskfmri_firstlevel_analysis_merge_step1.m and taskfmri_firstlevel_analysis_merge_step2.m), along with the onset files.


Could you please look into this and confirm if changing SPM.nsess from [152 152 152 152] to 608 is all that's needed to fix the issue?


Best regards,
Han


 


Originally posted by Alfonso Nieto-Castanon:



Hi,


Could you please let me know the details of how that merging was implemented? The error appears because in your SPM structure there is conflicting information regarding the number of sessions, the SPM.nsess field indicates that you have four sessions with 152 scans each, while the SPM.Sess field indicates that you have a single session with 608 scans. The simplest fix would be to change SPM.nsess from SPM.nsess=[152 152 152 152] (current state) to SPM.nsess=608. I believe that should let CONN import the information from those files normally. Please let me know otherwise.


Best


Alfonso


Originally posted by Han Lai:



​Hello, 

I encountered an error when trying to import data into CONN using the SPM.mat file from my SPM first-level analysis.

My preprocessing results are in 4D files, with each 4D file containing 152 3D images. During the first-level analysis, I merged 4 runs together for analysis. I've attached the first-level analysis results (including SPM.mat) for one subject. Could you please help me identify what's causing this error and how I should fix it?


 


[error]


Index exceeds the number of array elements (1).


Error in conn_importspm (line 85)
                if nsess>1, idxscans=spmfile.SPM.Sess(nses).row;


Error in conn_batch (line 768)
        conn_importspm(batch.Setup.spmfiles,args{:},'subjects',SUBJECTS);


 


[code for importing]


NSUBJECTS=size(sub_info,1);
batch.filename=fullfile(base_dir,'gppi','conn_gPPI_YanTian.mat');
if ~isempty(dir(batch.filename)), 
    Ransw=questdlg('conn_singlesubject_nopreprocesing01 project already exists, Overwrite?','warning','Yes','No','No');
    if ~strcmp(Ransw,'Yes'), return; end; 
end
batch.Setup.isnew=0;
%batch.parallel.N=size(sub_info,1);
% batch.parallel.N=4;


%%%%%%%%%%%% set up
batch.Setup.nsubjects=NSUBJECTS;
TR = 2; %second
batch.Setup.RT=TR;


% load 'SPM.mat'and standardized structural images
for nsub = 1:size(sub_info,1)
    cursubject = sub_info(nsub).name;
    STRUCTURAL_FILE = dir(fullfile(T1_outputdir,cursubject,'wLH*.nii'));
    STRUCTURAL_FILE = fullfile(T1_outputdir,cursubject,STRUCTURAL_FILE.name);
    if isempty(STRUCTURAL_FILE),return;end
    SPM_FILE = fullfile(firstlevel_outputdir,cursubject,'SPM.mat');
    if isempty(SPM_FILE),return;end
    batch.Setup.spmfiles{nsub}=SPM_FILE;
    batch.Setup.structurals{nsub}=STRUCTURAL_FILE;
end



 



 

Attachment: mergecode_lai.rar

Threaded View

TitleAuthorDate
Han Lai Nov 7, 2025
Alfonso Nieto-Castanon Nov 7, 2025
RE: RE: Encountered an issue with CONN data import
Han Lai 2 hours ago