MATLAB Answers

How do I store the changing values of a variable (generated in a for loop) into a single file without overwriting the previous one?

1 view (last 30 days)
Steve
Steve on 30 Oct 2019
Commented: Steve on 30 Oct 2019
For example:
n = 100;
for ii = 1 : n
areatriangle = .5*((ii/2)*ii);
end
In the case above, I want to store all the outcomes/iterations of areatriangle, not just the last one. How do I do this?
Thanks in advance for your help!

  0 Comments

Sign in to comment.

Accepted Answer

Alex Mcaulley
Alex Mcaulley on 30 Oct 2019
n = 100;
areatriangle = zeros(1,n)
for ii = 1 : n
areatriangle(ii) = .5*((ii/2)*ii);
end
or:
areatriangle = .5/2*(1:n).^2;

  7 Comments

Show 4 older comments
Alex Mcaulley
Alex Mcaulley on 30 Oct 2019
Ohhh yes, you need to change the following lines in the last loop:
ThetaInDegrees_a(j,pt) = acosd(CosTheta_a(j,pt));
ThetaInDegrees_b(j,pt) = acosd(CosTheta_b(j,pt));
ThetaInDegrees_c(j,pt) = acosd(CosTheta_c(j,pt));

Sign in to comment.

More Answers (0)

Sign in to answer this question.