Using a generated variable name as a handle for set function

조회 수: 4 (최근 30일)
Matt
Matt 2015년 9월 14일
댓글: Matt 2015년 9월 14일
Hello!
I would like to know how can I use a generated variable name to be used as a handle for the SET function. I have the current code:
for j=1:25
var=num2str(j, '%02i')
variable=['panel31.txt1' var]
if timematrix(menu.pm28, j)==1
set(variable, 'Color', 'g');
else
set(variable, 'Color', 'r');
end
end
However, I am getting the following error:
Error using set
Value must be a handle
How can I do this?

채택된 답변

Walter Roberson
Walter Roberson 2015년 9월 14일
for j=1:25
var=num2str(j, '%02i')
variable = sprintf('txt1%02i', j);
if timematrix(menu.pm28, j)==1
set(panel31.(variable), 'Color', 'g');
else
set(panel31.(variable), 'Color', 'r');
end
end
  댓글 수: 1
Matt
Matt 2015년 9월 14일
Fantastic, thank you very much! I ust had to change 'Color', to 'ForegroundColor' to suit my needs, but it works perfectly. Interesting way of doing, I've learned something!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by