Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
Timo Baumann
Timo Baumann am 10 Feb. 2020
Kommentiert: Timo Baumann am 11 Feb. 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 :)

Antworten (1)

Sindar
Sindar am 10 Feb. 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');

Kategorien

Mehr zu Workspace Variables and MAT-Files finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by