Looping on one line

18 Ansichten (letzte 30 Tage)
Patrick
Patrick am 7 Dez. 2015
Bearbeitet: Stephen23 am 19 Jun. 2019
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 Kommentar
Adam
Adam am 7 Dez. 2015
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 7 Dez. 2015
Bearbeitet: Stephen23 am 19 Jun. 2019

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by