Borrar filtros
Borrar filtros

Storing all for-loop results of a specific variable in .mat-file

2 visualizaciones (últimos 30 días)
Timo Baumann
Timo Baumann el 10 de Feb. de 2020
Comentada: Timo Baumann el 11 de Feb. de 2020
Hi guys,
after running my code, I'd like to store all calculated values of variable va in the file "d-va.mat", but when running the code shown below, it keeps overwriting the values and only shows the final result. Putting the "save" outside of the loop only gives me the first result.
_____________________________
%this is just a very easy example
for ta=1:20
a = 3;
va = (ta.*a)*3.6;
save('d-va.mat','va');
end
_____________________________
Would be awesome, if one of you could help me with this issue. It's probably very simple, but I can't figure it out :/
Thank you in advance :)

Respuestas (1)

Sindar
Sindar el 10 de Feb. de 2020
Assuming all the produced data can fit in memory:
for ta=1:20
a = 3;
% save each value in an array
va(ta) = (ta.*a)*3.6;
end
save('d-va.mat','va');

Categorías

Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by