Hello All
I am trying to design a GUI in which the number of radio buttons change according to the number calculated by another function. The important thing is, although I am able to get the GUI, I am not able to access the radio buttons being created. I can use gcbo. But I can't distinguish between the buttons.
for i = 1:5
handles.tr(i) = uicontrol('Style','radiobutton','String','Translation',... 'pos',[40 (1+(i*30)) 100 30],'HandleVisibility','off');
set(handles.tr(i),'Callback',@selcbk);
handles.flag_tr = 1;
handles.check_tr = 1;
end
But when I try to access the radio buttons, I can only do that using gcbo. Could you suggest some method by which I can distinguish between the buttons and hence, access them?

댓글 수: 3

Jan
Jan 2013년 8월 9일
I do not get the problem. You overwrite handles.flag_tr and .check_tr in each iteration.
nl2605
nl2605 2013년 8월 9일
Yea, I don't need to. I know that. But I don't know where else to declare the variables. I have used GUIDE always to construct GUI's. This is the first time I making my own code. Anyway the issue is that I don't know how to access the properties of the radiobuttons being made.
Jan
Jan 2013년 8월 9일
And does my answer help you in any way?

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

 채택된 답변

Jan
Jan 2013년 8월 9일

0 개 추천

The problem is not clear to me. Perhaps this helps:
handles.flag_tr = 1; % Once only
handles.check_tr = 1;
for i = 1:5
handles.tr(i) = uicontrol('Style','radiobutton','String','Translation',...
'pos',[40 (1+(i*30)) 100 30],'HandleVisibility','off', ...
'Callback',@selcbk);
end
guidata(FigureHandle, handles);
...
function selcbk(ObjectH, EventData)
handles = guidata(ObjectH);
allBoxes = handles.tr;
selectedBox = ObjectH;
otherBoxes = allBoxes(allBoxes ~= selectedBox);

댓글 수: 3

nl2605
nl2605 2013년 9월 27일
It didn't help really..its giving me more number of errors than before!
nl2605
nl2605 2013년 9월 27일
Its just that I need to produce a certain number of radio buttons(the number decided by another function). The radio buttons should appear in columns of two, where each column represents lets say a decision. I can produce the radio buttons. But I am not able to store which is getting selected by the user.
nl2605
nl2605 2013년 9월 27일
편집: nl2605 2013년 9월 27일
Phew!! This worked. Thanks a lot! It was my mistake it was giving errors.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 9월 27일

0 개 추천

How about you use GUIDE to place all of the radio buttons that you might ever need on the GUI, and then jsut set the visibility property to on or off depending if you want it to appear or not?
set(handles.radio1, 'Visibility', 'on');
set(handles.radio2, 'Visibility', 'on');
set(handles.radio3, 'Visibility', 'off');
set(handles.radio4, 'Visibility', 'off');

댓글 수: 6

nl2605
nl2605 2013년 9월 27일
편집: nl2605 2013년 9월 27일
Hi..I am not using GUIDE as the number of radio buttons that I want will be calculated and will change whenever I run my program again.
Image Analyst
Image Analyst 2013년 9월 27일
That's not a reason for not using GUIDE. I think you didn't understand what I said.
nl2605
nl2605 2013년 9월 27일
편집: nl2605 2013년 9월 27일
I thought you said that I should for example put 20 radio buttons and use 10 of them by changing visibility? But what if my program in some later stage needs 21 radio buttons.
And if this works. Then lets say I need only 5 radio buttons to appear, then how can I put it in a for loop. Because I can access the radiobutton Visibility property using its Tag.
I am sorry but I have been stuck with this problem for a very long time now. :/
Image Analyst
Image Analyst 2013년 9월 27일
Yes, if the most buttons you can ever have is, say, 25, then put 25 on there. In the opening fcn you can put the handles of the radio buttons into an array (just like Jan did). Then, say, a popup (drop down list) callback indicates that you should have 10 showing. So you then run a loop (like Jan did) where you set the visibility of radio buttons 1-10 "on", and 11-25 "off". But anyway, it looks like you're successfully using Jan's method so you're all set. Jan is a fan of the do-it-yourself method while I'm a fan of the GUIDE method.
nl2605
nl2605 2013년 9월 27일
편집: nl2605 2013년 9월 27일
Hmmm..I like the GUIDE way too. But I thought this problem wouldn't have a solution with GUIDE. But I am slowly learning there isn't any 'no solution'. Thanks a lot. By the way can I accept both your solutions for future reference for others?
nl2605
nl2605 2013년 9월 27일
Ohh I don't think so I can. But anyway thanks a ton!

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

카테고리

도움말 센터File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

질문:

2013년 8월 9일

댓글:

2013년 9월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by