Output of every loop calculation to be used as vector.

1 次查看(过去 30 天)
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???...

回答(1 个)

Sean de Wolski
Sean de Wolski 2011-6-23
y = zeros(n,1);
for ii = 1:n
y(ii) = some_value_of_x(possibly(ii))
end
  6 个评论
Stephen23
Stephen23 2020-2-14
"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 2020-2-14
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by