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

6 views (last 30 days)
Steve on 30 Oct 2019
Commented: Steve on 30 Oct 2019
For example:
n = 100;
for ii = 1 : n
areatriangle = .5*((ii/2)*ii);
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!

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);
areatriangle = .5/2*(1:n).^2;

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!