-1

I would like to find a programmatic way to toggle a toggle button in Matlab's GUI (built by GUIDE). The button has a callback function, that uses the second input (eventdata, that's quite rare). However, calling this function from outside the GUI failed. I'm not interested only in the visual effect of the on/off, but to provoke the appropriate callback (depending on the state of the button). Any ideas?

NoamG
  • 137
  • 9
  • Please add your code which has failed. – Lati Jun 20 '16 at 07:50
  • eventdata is an object that can't be saved or reused. I guess it's needed for activating the button, but I couldn't generate it by myself. Unlike calling other callbacks made by GUIDE (where eventdata is usually empty), here I found it missing. The buttom line is this: how can I toggle that button programmatically, as if I was pressing on it with the mouse? – NoamG Jun 20 '16 at 10:14

1 Answers1

0

eventdata for the toggle button has not yet defined (I am using v2012). It is written below the callback function as a comment “eventdata reserved - to be defined in a future version of MATLAB”. Therefore you can use any value when you call the toggle button callback. For example if your toggle buttons tag is togglebutton1 and its callback function is togglebutton1_Callback :

togglebutton1_Callback(handles.togglebutton1, 0, handles);

will call the toggle button callback. If you want to change the state of the toggle button, then set its value to 1 for pushed state and 0 to not pushed.

set(handles.togglebutton1, 'value', 1);
Lati
  • 341
  • 6
  • 18
  • Although Matlab keeps the statement that eventdata is saved for future use, in R2014 it is already in use. Check it out. The solution you offered was already checked. However, it's still not good enough, because when calling the callback, eventdata is required for the updated state of the button. – NoamG Jun 26 '16 at 21:43
  • I could finally test it with Matlab 2015b. As I can see, toggle button has passes eventdata which has 2 properties: Source (which is toggle button properties) and EventName. You can still call the toggle button callback using following statement: "togglebutton1_Callback(handles.togglebutton1, [], handles);" – Lati Jul 01 '16 at 19:18