How to save for loop values?

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by