Incrementing handles names in a loop

조회 수: 1 (최근 30일)
Marcin
Marcin 2011년 5월 31일
Hi, I went through many MATLAB answers and posts, but still can not resolve a simple problem: I have many radiobuttons in my GUI. I want to assign values in an array based on the radiobutton state. I can do it "one by one" but to shorten the code, I would like to make it in a loop. However I can not succeed with incrementing the radiobutton number, as I would do with a simple variable (say A1, A2, A3, etc...). Can somebody help me with the correct syntax? Here is the portion of my code that doesn't work:
for i = 1:20
if (get('handles.radiobutton'num2str(i), 'Value') == 1)
ClassArray(i,2) = 1
elseif (get('handles.radiobutton'num2str(i), 'Value') == 0)
ClassArray(i,2) = 0
end
end
Thanks,
Marcin

채택된 답변

Walter Roberson
Walter Roberson 2011년 5월 31일
for i = 1:20
thishandle = sprintf('radiobutton%d', i);
ClassArray(i,2) = get(handles.(thishandle), 'Value');
end
  댓글 수: 1
Marcin
Marcin 2011년 5월 31일
Thanks a lot!
I was just reading the FAQ you pointed out before...
This resolves my problem.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by