Alternatives for 'eval' command?
1 回表示 (過去 30 日間)
古いコメントを表示
Hello. I've discovered eval command to solve some of my problems. But also I've just read that's inefficient and threaten (!del *.m") too. Any suggestion to improve my code? It's like this example, where I want to apply some algebra/functions to different fields (names_2) of main variables (names_1), which are structures. Thanks in advance.
Var_1.cast1=rand(5,10);Var_1.cast2=rand(7,20);Var_1.cast3=rand(4,8); Var_2.cast1=rand(3,10);Var_2.cast2=rand(9,20);Var_2.cast3=rand(6,8);
for k=1:2
names_1{k}=strcat('Var_',num2str(k));
end
for k=1:3
names_2{k}=strcat('cast',num2str(k));
end
for k=1:length(names_1)
v=genvarname(names_1{k});
for i=1:length(names_2)
aux_var=eval([v '.(names_2{i});']);
aux_var_2.(names_2{i})=aux_var(:,2:end)';
end
eval([v '=aux_var_2;'])
clear v aux_var aux_var_2
end
0 件のコメント
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!