Cellstr error in my program: Where is my mistake?

Hi, My program is the following:
s = dir('./sub*/*.*');
for kk = 1:numel(s);
if ~s(kk).isdir
dicomfiles = 1:numel('./sub*/*.*');
fd=spm_file(dicomfiles(1,:), 'fpath');
cd(fd);
hdr=spm_dicom_headers(dicomfiles);
spm_dicom_convert(hdr, 'all', 'series', 'nii')
else
end
msgbox ('done' , 'OK')
end
I am trying to get the program to read all folders containing the word sub and then in each folder convert the files and then loop to go through each folder, then the files, etc.
I am currently getting the errors:
Error using cellstr (line 49)
Conversion to cellstr from double is not possible.
Error in spm_file (line 63)
str = cellstr(str);
Error in LoopDcmConv (line 5)
fd=spm_file(dicomfiles(1,:), 'fpath');
Would someone be able to tell me where to change the program to make it run properly?

2 Comments

This is strange as it will always return the array [1 2 ... 10]
1:numel('./sub*/*.*')
so, the next line will return a strange character array
I can change that command to 1:160, since I know how many files I want to read per folder, when I change that it gets rid of the line 5 error

Sign in to comment.

Answers (0)

Categories

Asked:

on 4 Oct 2018

Commented:

on 4 Oct 2018

Community Treasure Hunt

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

Start Hunting!