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..
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!