How to call a UIButtonGroup SelectionChangeFunction
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi! I have a few toggle buttons in a UIButtonGroup and all is well. However, in some circumstances I want to change the state of the buttons programmatically and I naively thought I could do it by simply calling the "SelectionChangeFunction" function with an appropriately defined eventdata structure. This almost works. The function does what I want but I guess I confused the UIButtonGroup in some way because subsequent clicks on buttons make it behave strangely. It basically doesn't realize that I have programmatically clicked on a button and "remembers the "old state". I tried setting the "SelectedObject" to my desired button (hoping that would automagically call the function) but.... nuttin.
Do I need to be "triggering an event"? I'm not sure how to do this.... Advice?
Dan
댓글 수: 0
답변 (2개)
Image Analyst
2014년 1월 2일
Just have the button group callback call another function called ButtonClicked.
function handles = ButtonClicked(handles)
% Now do whatever you want.
Now that will get called when the user clicks on a button, plus you can also call it whenever you want from any function at all.
David Stapleton
2016년 2월 15일
I was having the same problem and stumbled into a simple workaround. I'm not sure if this solution is bug-free, but it's working for me. Basically combine the two methods you started with, calling the function with spoofed eventdata and immediately resetting the SelectedObject so that it matches. You can reset before or after you call the function, as long as you pulled the previous value to use for the OldValue in the spoofed eventdata.
eventdata.OldValue=Group.SelectedObject;
eventdata.NewValue=Option2;
eventdata.Source=Group;
eventdata.EventName='SelectionChanged';
Group.SelectedObject=Option2;
SelCngd(Group,eventdata);
As far as I can tell, calling the function gets you all of the results of an actual event while ignoring SelectedObject and manually changing that doesn't have any follow-up effects.
I also tried to use notify() but all I got was: No method 'notify' with matching signature found for class 'matlab.ui.container.ButtonGroup'.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!