Alternate form of eval function
Show older comments
How can I write these two syntaxes in alternate from?
eval(['I',num2str(i),num2str(j),num2str(k),'=','getsiganl(filename1)',';']);
eval(['II',num2str(i),num2str(j),num2str(k),'=','smooth(sum(I',num2str(i),num2str(j),num2str(k),',2)',');']);
1 Comment
Rather than trying to use an "Alternate form of eval function", you should just write your code using much simpler and much more efficient indexing. Is there a particular reason why you cannot use indexing?
Accepted Answer
More Answers (1)
Matt J
on 18 Mar 2021
Why not simply
I(i,j,k)=getsiganl(filename1);
II(i,j,k)=smooth(sum(I(i,j,k),2))
Be mindful though that if i,j,k are scalar coordinates, neither the original eval form nor the above make sense.
2 Comments
Bjorn Gustavsson
on 18 Mar 2021
If getsiganl returns a 2-D matrix it kind of makes sense, note that the eval-version would generate variables with names like I123 for i = 1, j = 2 and k = 3 and then the completely inuntangleable _I1234 for all of [i, j, k] = [12, 3 4], [1 23 4] or [1 2 34]...
Wiqas Ahmad
on 18 Mar 2021
Categories
Find more on Matrix Indexing 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!