How to save for loop values?

1 view (last 30 days)
Qasim Mohammed
Qasim Mohammed on 28 Feb 2020
Commented: Star Strider on 28 Feb 2020
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.

Accepted Answer

Star Strider
Star Strider on 28 Feb 2020
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 Comments
Qasim Mohammed
Qasim Mohammed on 28 Feb 2020
Thanks, it was helpful!
I need then as two columns, I transposed them.
Star Strider
Star Strider on 28 Feb 2020
As always, my pleasure!

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!