Create vector for data after each iteration of a for loop
Show older comments
I can't seem to figure out how to make a vector that after each iteration of a for loop takes the value of the set variable, and adds a data point. Below I added a pseudo-code example of what I'm trying to accomplish. When I try to make anything of the sort, it just overwrites the previous value.
y = x;
z = 0*y;
for n = 0:N
z = Z+1+2.*n
end
How can I, after N iterations, make a column vector(e.g. Vect) that does the following:
Iteration 1:
N = 0;
z = 1;
Vect [1]
Iteration 2:
N = 1;
z = 4;
Vect [1,4]
Iteration 3:
N = 2;
z = 9;
Vect [1,4,9]
etc... ??
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!