Reverse of eval in MATLAB
I hope if someone has a bit of experience in MATLAB than I do can help here, I am a bit hopeless with this MATLAB thing.
I have a list of variable in MATLAB called S50
, S60
, S70
and so... with dimension 1x142x192
. I simply wanted to combine th开发者_JAVA技巧em into one variable to run a statistical analysis on it (into dimension Nx142x192
).
I found people use eval
function to create string of variable, can I do the reverse?
for i = 1:5
eval([ 'M' num2str(i) ' = M;' ]);
end
Although I don't really like using EVAL, here is one possible solution:
%# evaluates the expression: cat(1,S50,S60,S70)
S = eval(['cat(1' sprintf(',S%d', (50:10:70)') ')']);
精彩评论