Problem-saving the results from the loop

1 回表示 (過去 30 日間)
katyam Kepes
katyam Kepes 2019 年 6 月 21 日
編集済み: Aravind Ravikumar 2019 年 6 月 21 日
Hello. I need help
I have this code, I want to save the results from Sbar1.
Nn=4;
for i=1:1:Nn
for X1=0:45:360
c= cos(X1*pi/180)
s= sin(X1*pi/180)
R= [1 0 0; 0 1 0; 0 0 2]
A1= [c^2 s^2 2*s*c; s^2 c^2 -2*s*c; -s*c s*c c^2-s^2]
Sbar1= [R*A1^-1*R^-1*S*A1]
end
end

採用された回答

Aravind Ravikumar
Aravind Ravikumar 2019 年 6 月 21 日
編集済み: Aravind Ravikumar 2019 年 6 月 21 日
Thanks Madhan Ravi for the idea,
You could apppend the values of Sbar1 at each iteration to another variable, say result like this
Nn=4;
result = double.empty(0,3);
for i=1:1:Nn
for X1=0:45:360
c= cos(X1*pi/180);
s= sin(X1*pi/180);
R= [1 0 0; 0 1 0; 0 0 2];
A1= [c^2 s^2 2*s*c; s^2 c^2 -2*s*c; -s*c s*c c^2-s^2];
Sbar1= [R*A1^-1*R^-1*s*A1];
result = [result,Sbar1]
end
end
Here first 3 columns of result will be the Sbar1 of first iteration, next 3 columns will be Sbar1 of second iteration, and so on.

その他の回答 (1 件)

Aravind Ravikumar
Aravind Ravikumar 2019 年 6 月 21 日
I'm assuming by save, you mean to write the data into an external file. Have a look at save() (documentation here).
With this, you can save workspace variables into a file and you can set various options like the file type, the variables, the format, etc.
  2 件のコメント
madhan ravi
madhan ravi 2019 年 6 月 21 日
編集済み: madhan ravi 2019 年 6 月 21 日
No , the OP wants to save the results of each iteration into the variable.
Aravind Ravikumar
Aravind Ravikumar 2019 年 6 月 21 日
Ohh thinking now, I think that seems more sensible.

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

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by