Add string files to a cell array within a loop
Afficher commentaires plus anciens
Hi!!
I am creating a preprocessing fmri pipeline and wanted to ge the names of all the files from each run of a subject in a cell array. So if the subject did 3 runs I would have a 1x3 cell array where each cell would correspond to a run.
I am getting the files names in the following loop:
user = 'user';
subjects = [1]; % Replace with a list of all of the subjects you wish to analyze
runs = [1 2 3];
for subject=subjects
runFiles = cell(1,length(runs));
for run = runs
subject = num2str(subject,'%02d');
run = num2str(run);
fileName = ['C:\Users\',user,'\Documents\BIDS__dataset\sub-',subject,'\ses-01\func\sub-PL',subject,'_ses-01_task-01_run-',run,'_bold.nii'];
runFiles(run) = fileName;
end
end
But when I try to add the file name to the cell array I get the error "Conversion to cell from char is not possible."
I tried to to
runFiles(run) = cellstr(fileName);
and
runFiles{run} = fileName;
but I end up with a 1x51 cell array instead of a 1x3.
For reference, I would like to end up with something like:
{
{'C:\Users\user\Documents\BIDS__dataset\sub-PL01\ses-01\func\sub-01_ses-01_task-01_run-1_bold.nii'}
{'C:\Users\user\Documents\BIDS__dataset\sub-01\ses-01\func\sub-01_ses-01_task-01_run-2_bold.nii'}
{'C:\Users\user\Documents\BIDS__dataset\sub-01\ses-01\func\sub-01_ses-01_task-01_run-3_bold.nii'}
};
Thank you in advance!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Whos dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!