Promble creating a variable with loop

4 views (last 30 days)
Andre Leitao
Andre Leitao on 10 Nov 2018
Answered: Walter Roberson on 10 Nov 2018
Hello guys. I want to implement this code:
[nii_file,pathname] = uigetfile('*.nii','Select Time Points','MultiSelect','on')
if isequal(nii_file, 0)
disp('User selected Cancel')
return;
end
for k = 1:length(nii_file)
a.(nii_file{k}) = niftiread(nii_file{k});
end
but it gives me the error: Invalid field name: 'FileName.nii'.
The files '.nii' are matrices of 128x128x128 int16
Can it be done by this method?
Regards

Answers (1)

Walter Roberson
Walter Roberson on 10 Nov 2018
Use fileparts() to strip off any directory and suffix.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!