Matlabbatch in the SPM, Item 'Session', field 'val': Value must be either empty, a cellstr or a cfg_dep

45 views (last 30 days)
I am creating a matlabbatch for relignment in SPM, Matlab.
I am looping through the runs (8) and images (482 per run), but get a following error:
Item 'Session', field 'val': Value must be either empty, a cellstr or a cfg_dep.
I have created a sample batch in SPM and opened the code. I discovered that each path to the image i the matlabbatch ends with ...nii, 1
But the paths that I add to images are all ending with .nii. Could that create a problem? I have tried to append the path with ", 1", but all the solutions I have tried change the cell number in the batch and create another error.
Right now my data in matlabbach is 8 columns with 482x1 cell each (482 images for each run i each cell). Each column represents one session in SPM GUI in my understanding. Could someone please help me with that? - appending the image_file path with ",1" if that can cause an issue or explain what other issues there could be. Here are the loops in my code.
for run = 1:length(run_folders)
image_path = fullfile(sub_dir, run_folders(run).name);
fprintf('Checking image path: %s\n', image_path);
% Getting the volumes
image_file = dir(fullfile(image_path, sprintf("fConcept_RelRel_Pilot_%s_run%d_*.nii", subjects{sub}, run)));
num_images = length(image_file);
matlabbatch{1}.spm.spatial.realign.estwrite.data{run} = cell(num_images, 1);
% Filling the data_cell with image paths
for image = 1:num_images
matlabbatch{1}.spm.spatial.realign.estwrite.data{1,run}{image,1} = cellstr(fullfile(image_path, image_file(image).name));
end
end

Answers (1)

Manikanta Aditya
Manikanta Aditya on 12 Nov 2024 at 16:52
Hi,
I found a relevant MATLAB Answer which talks about the similar issue you encountered. Refer to it to see if you can find any resolution for it.
I hope this helps.

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!