Loading variable from whos
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi I am working on a group of variables, and I want work on every of them changing them value in loop.
I grouped interested me variables by whos('I2*')
Thank You.
댓글 수: 0
채택된 답변
Jan
2013년 6월 18일
Avoid such meta-programming. Guessing the names of the variables and construct some obscure EVAL command to access them increases the complexity of your program without any benefit.
If the variables belong together, define them as fields of a struct. Then dynamic field names allow a fast and save processing:
a.x = 1:10;
a.y = rand(10);
fields = fieldnames(a);
for k = 1:length(fields)
disp(a.(fields{k}));
end
추가 답변 (1개)
David Sanchez
2013년 6월 18일
Try this out:
my_vars=whos;
for k = 1:length(my_vars)
assignin('base',my_vars(k).name,value_to_assign)
end
where value_to_assign is jsut that, the value you want the variable to have.
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!