How to call a UIButtonGroup SelectionChangeFunction
9 次查看(过去 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!