Output of every loop calculation to be used as vector.

1 view (last 30 days)
Dear Friends,
I want an output element of every loop calculation, which can be used as a separate vector. Following is an example:
Suppose, after very loop(if-else or for) calculation, gives the value of some variable, say x. After coming out of loop, I want to use all the calculated values of x, as a separate vector, say y, so that the vector y will be
y=[1st value of x in 1st loop 2nd value of x in 2nd loop & so on...];
Can any of you please help me to get such output???...

Answers (1)

Sean de Wolski
Sean de Wolski on 23 Jun 2011
y = zeros(n,1);
for ii = 1:n
y(ii) = some_value_of_x(possibly(ii))
end
  6 Comments
Stephen23
Stephen23 on 14 Feb 2020
"Could you please help me with that?"
LIke the examples on this page show, you should loop over indices, not data values.
"I'd like to store the vectors of cs, wsmax, thetas and Wnutz in seperate vectors"
You could use a cell array for that, although I strongly recommend putting indentically-sized numeric data into one numeric array rather than storing it as separate vectors.
Timo Baumann
Timo Baumann on 14 Feb 2020
Ok thanks :)
The reason I'd like to store everything in seperate vectors is that I'd like to display every variable depending of another one as I want in order to see the influence of each variable individually.
Thanks again for your help.

Sign in to comment.

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!