Alternatives for 'eval' command?

조회 수: 4 (최근 30일)
Miguel Ángel
Miguel Ángel 2013년 10월 3일
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개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by