how can save all variables which are in function without deleting previous one ?
28 views (last 30 days)
how can save all variables which are in function ? i would like to extract those variables out of function. if i just use "save" command in function, it will delete just previous variable. however, i need all of them not the last one. can anyone help
Majid Farzaneh on 21 Nov 2018
You can make a string in each run for your function and then use the string for your file name. for example you may use a global counter in function like this:
str=['file' , num2str(counter) , '.mat'];
More Answers (1)
Cris LaPierre on 21 Nov 2018
The specifics are a little unclear, but here are some options.
Consider saving them to a mat file with a unique filename. However, they will still contain the same variable names, so when loaded back into the workspace, will replace any existing variables with the same names.
You could return them through the function output. That allows you to assign them to variables with whatever name you want, allowing you to have both at the same time.
If there are a lot of variables, consider using a structure so you only have to pass out one variable.