saving matlab file (.mat) with dynamic name

314 views Asked by At
for m = 1:length(lst_region)
out=cellfun(@(x) str2double(x(1:strfind(x,'_')-1)),lst_region(m));
str=[num2str(out(1)) '.mat'];
save ( str ,distance);
end

Error using save Argument must contain a string. Line 3

I want to save files like '1.mat' '2.mat' etc.. but i have error can you please help me to fix it

1

There are 1 answers

0
Pieter12345 On BEST ANSWER

If distance is a variable in your workspace, you will have to call save(str, 'distance');. You have to enter the name of the variable, not the variable itself.