append/save same variable with updated values without overwriting previous values.

5 ビュー (過去 30 日間)
Armel
Armel 2013 年 10 月 22 日
回答済み: Walter Roberson 2013 年 10 月 22 日
Hi, Let's say I have a variable called Stress that I would like to save at each end of each loop.
Stress=[1 2 3 4 5] "1st loop", Stress=[6 7 8 9 10] "2nd loop", Stress=[11 12 13 14 15] "3rd loop".
How can I save the results in matlab so that when I open the mat-file, I get a nice table with 1st row showing the Stress values of the 1st loop, 2nd row showing the Stress values of the 2nd loop and so on.
I tried save(filename,Stress,-append) but values get overwritten maybe because the variable name (stress) remains unchanged. If that's the case, how can make the variable string (Stress) in the save function dynamic? Thank you

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 22 日
編集済み: Azzi Abdelmalek 2013 年 10 月 22 日
stress=zeros(3,5);
for k=1:3
stress(k,:)=[1 2 3 4 5]; % adapt this line to your problem
end
% There is another way, but make your code slower
stress=[];
for k=1:3
stress=[stress;1 2 3 4 5]
end
  1 件のコメント
Armel
Armel 2013 年 10 月 22 日
Thank you Azzi, However this is not quite what I'm looking for. But it just gave me a new idea that I would like to try. Thanks

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


Walter Roberson
Walter Roberson 2013 年 10 月 22 日

カテゴリ

Help Center および File ExchangeStress and Strain についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by