Looping on one line

15 次查看(过去 30 天)
Patrick
Patrick 2015-12-7
编辑: Stephen23 2019-6-19
I searched the forums and couldn't find anything like this. So either I am doing it completely wrong or there is another method to accomplish it. Here is the code
if true
% code
SpearMeanRhoAll = vertcat(SpearMeanRhoP2,SpearMeanRhoP3,SpearMeanRhoP4,SpearMeanRhoP5,SpearMeanRhoP6,SpearMeanRhoP7,SpearMeanRhoP8,SpearMeanRhoP9,SpearMeanRhoP10,SpearMeanRhoP11,SpearMeanRhoP12,SpearMeanRhoP13,SpearMeanRhoP14,SpearMeanRhoP15,SpearMeanRhoP16,SpearMeanRhoP17,SpearMeanRhoP18,SpearMeanRhoP19,SpearMeanRhoP20,SpearMeanRhoP21);
end
As you can see the variable "SpearMeanRhoAll" is composed of SpearMeanRhoPx where x goes from 2 to 21. Does anyone know how to loop like this on one line?
Thanks for any help.
  1 个评论
Adam
Adam 2015-12-7
How to do what in a loop? Loops are not generally meant to be done in one line other than loop-replacement functions like arrayfun.
In general you should never put yourself in a situation where you have 21 variables with names like that in the first place. Your SpearMeanRhoAll representation would be far better to be used right from the start.

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2015-12-7
编辑:Stephen23 2019-6-19

更多回答(0 个)

类别

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