フィルターのクリア

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

2 ビュー (過去 30 日間)
Timo Baumann
Timo Baumann 2020 年 2 月 10 日
コメント済み: Timo Baumann 2020 年 2 月 11 日
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');
  1 件のコメント
Timo Baumann
Timo Baumann 2020 年 2 月 11 日
Thank you for your quick response!
That works :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeWorkspace 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