I would like to save different variables (included in the same cell) using cellfun.
As an example, this is the cell containing the file names for the 3 files that will be created:
fnames={'var1.mat';'var2.mat';'var3.mat'};
And this is the cell with the variables that will be saved in the corresponding files:
vars={ones(1);2*ones(3);3*ones(3)};
As far as I understand, arrayfun could save vars{1} with the name 'var1.mat', vars{2} with the 'var2.mat', and vars{3} with 'var3.mat'. But I get the following error:
cellfun(@(x,y) save(x,y), fnames,vars)Error using saveArgument must contain a character vector.Error in @(x,y)save(x,y)
If I try the following code I get another error:
cellfun(@(x,y) save(x,y), fnames,'vars')Error using cellfunInput #3 expected to be a cell array, was char instead.
I don't really know if the syntax is not correct or what I'm trying to do is not possible.
Any ideas about it?
Many thanks!!
Best Answer