Looping on one line

18 visualizzazioni (ultimi 30 giorni)
Patrick
Patrick il 7 Dic 2015
Modificato: Stephen23 il 19 Giu 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 Commento
Adam
Adam il 7 Dic 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.

Accedi per commentare.

Risposta accettata

Stephen23
Stephen23 il 7 Dic 2015
Modificato: Stephen23 il 19 Giu 2019

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by