Alternative to using eval function

3 次查看(过去 30 天)
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..

采纳的回答

Walter Roberson
Walter Roberson 2011-12-13

更多回答(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