Looping on one line
18 次查看(过去 30 天)
显示 更早的评论
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
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.
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!