Alternative to using eval function

3 views (last 30 days)
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..

Accepted Answer

Walter Roberson
Walter Roberson on 13 Dec 2011

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!