How to call a UIButtonGroup SelectionChangeFunction
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Image Analyst
am 2 Jan. 2014
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.
2 Kommentare
David Stapleton
am 15 Feb. 2016
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 Kommentare
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!