How to execute checkbox callback by using pushbutton callback

Hi,
I will be thankful if you could help me in this. I am new to matlab, i would like to click the pushbutton and in the same time it should execute the checkbox or listbox callback(similar to clicking the checkbox/listbox). How can i do this.

1 Comment

This looks much like a shorter version of the Question http://www.mathworks.com/matlabcentral/answers/38850-need-help-how-to-develop-an-gui-with-callbacks

Sign in to comment.

 Accepted Answer

h = HandleOfOtherControl;
cb = get(h, 'Callback'); %this retrieves the callback
cb{1}(h, [], cb{2:end}); %this invokes the callback
Warning to other readers: this sequence will not work for callbacks constructed by GUIDE, as those use are strings instead of cell arrays of that contain the function handle. Fortunately Karthick KJ does not appear to be using GUIDE (or at least has not mentioned using GUIDE in any posting.)

7 Comments

Hi Walter, thanks for the reply. I have used GUIDE for creating the checkbox and Listbox. Do you mean this is valid only for those created with UICONTROL?
GUIDE creates uicontrol() objects. However, GUIDE uses the string form of a callback, counting on the string to be feval()'d when the callback is invoked. The above code does not work for callbacks that are strings. You still need to get() the Callback, but you need to
feval(cb, h, [])
or something like that.
Hi Walter, I got an answer from Ketan on the similar question. Which method is more efficient ?
http://www.mathworks.com/matlabcentral/answers/38850-need-help-how-to-develop-an-gui-with-callbacks
I know that one can simulate a button press (invoke the button press callback) from the commandline. So I would guess this is possible with the checkbox callback too. See uploaded example here (4kb in size so RS displays 0.00mb which is true, so dont worry)
https://rapidshare.com/files/3164161050/pass_data_to_gui_and_simulate_button_press.zip
But when you call your GUI from a GUI callback make sure you dont enter any endless recursion.
Hello Friedrich,
Thanks alot for your answer :-) very short and effective. It worked for me.
Writing a common routine to be called by both callbacks makes clearer code, but invoking the stored callback for a function makes the callbacks more independent.
Ok. I just used the callback to listbox from the checkbox.
sp2_V04('listboxyaxis_tag_Callback',handles.listboxyaxis_tag,[],handles)

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!