Alternative to using eval function

3 visualizzazioni (ultimi 30 giorni)
li
li il 13 Dic 2011
Hi guys
I have been working on something that requires me to generate dynamically 2 things
A: variables B: code to loop through the variables.
and yes the variables are things like Theta1,Theta2.... However depending on inputs, the dimension of these arrays will change from one to another, hence the reason im not using a higher dimensional array.
The allocation of variable part dont seem to be too slow however, when i attempt to loop through all the variables using eval iteratively in the following manner:
eval(strcat('Theta',index,'*x',index.....)); %where index is just a character denoting the iteration number... it becomes very very slow...
Im not yet very familiar with matlab, so i would like to ask you guys if there is a better way of doing this, maybe some other way of calling variable from string format? or as i read from some other posts possibly the use of structure?
Much appreciated..

Risposta accettata

Walter Roberson
Walter Roberson il 13 Dic 2011

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