I want to load multiple variables into one .mat file at the end of a process loop. I have a simple line of code :
save draw.mat Output
but I cannot work out a way to code ‘use the name given by variable X’ instead of ‘Output’, so that I can loop the process and save multiple variables in draw.mat
So then
X = 'Chocolate'
and the Variable name is saved as Chocolate.
I am sure it is simple but I cannot find a solution on here!
You can use the
-structform of thesavecommand. You build a struct with fields holding the names of the variables in the resulting .mat-file.Example:
The file draw.mat will now hold two 1×1 double variables with names “VariableOne” and “VariableTwo”.
You can also build the struct in one single command:
Or you can use the
cell2structfunction: