Using variable names for saving data

16 views (last 30 days)
I am running a for loop for parametric sweep. After each loop, the data is to be saved within a .mat file using the 'save' command. How do I provide the function names so that each parameter gets its own .mat file after each loop completion?

Accepted Answer

Walter Roberson
Walter Roberson on 29 Jun 2015
for K = 1 : 20
filename = sprintf('data%04d.mat', K);
save(filename, 'VariableName');
end
If you have more than 9999 iterations then increase the 4 to the maximum number of digits you need.
  1 Comment
Sudipta Ray
Sudipta Ray on 30 Jun 2015
Thank you Walter. The parametric sweep is for not more than 10 values, so the last part is not an issue.

Sign in to comment.

More Answers (0)

Categories

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

Tags

Community Treasure Hunt

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

Start Hunting!