Using variable names for saving data

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?

 Respuesta aceptada

Walter Roberson
Walter Roberson el 29 de Jun. de 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 comentario

Sudipta Ray
Sudipta Ray el 30 de Jun. de 2015
Thank you Walter. The parametric sweep is for not more than 10 values, so the last part is not an issue.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 29 de Jun. de 2015

Comentada:

el 30 de Jun. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by