开发者

Reverse of eval in MATLAB

开发者 https://www.devze.com 2023-03-23 15:38 出处:网络
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 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)') ')']);
0

精彩评论

暂无评论...
验证码 换一张
取 消