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

2 次查看(过去 30 天)
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 :)

回答(1 个)

Sindar
Sindar 2020-2-10
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');

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by