How to save for loop values?

1 回表示 (過去 30 日間)
Qasim Mohammed
Qasim Mohammed 2020 年 2 月 28 日
コメント済み: Star Strider 2020 年 2 月 28 日
f=zeros(1,M);
for i=1:M
f(i)=fd+((1+m(i)*r)/2)*f_delta;
f(i)=fd-((1+m(i)*r)/2)*f_delta;
end
I need to save both values for the addition and subtraction.
Thanks in advance.

採用された回答

Star Strider
Star Strider 2020 年 2 月 28 日
Try this:
f=zeros(2,M);
for i=1:M
f(:,i)=[fd+((1+m(i)*r)/2)*f_delta; fd-((1+m(i)*r)/2)*f_delta];
end
That saves them as different rows of a (2xM) matrix.
  2 件のコメント
Qasim Mohammed
Qasim Mohammed 2020 年 2 月 28 日
Thanks, it was helpful!
I need then as two columns, I transposed them.
Star Strider
Star Strider 2020 年 2 月 28 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by