简体   繁体   中英

How to assign one function to different UI controls in GUIDE?

I have a set of push-buttons in a figure designed in GUIDE and I want to assign one single function as their callback functions. But there is no combo-box to choose my function from in the property inspector, and when I select all buttons and click Callback from View Callbacks menu it creates multiple callback functions. Same behavior when I hit the I-DON'T-KNOW-WHAT-TO-CALL button in the property inspector.

I can handle this with some coding in OpeningFcn like what described here or just with calling set(handle, 'method') , but I really prefer to do it in the designing environment.

You can edit the Callback value within the Property Inspector. By default, it will be a custom callback for that uicontrol, but you can change it to be whatever you want.

在此处输入图片说明

So for me, for two push buttons they are something like the following by default:

@(hObject,eventdata)mygui('pushbutton2_Callback',hObject,eventdata,guidata(hObject))    
@(hObject,eventdata)mygui('pushbutton1_Callback',hObject,eventdata,guidata(hObject))

Just copy the value of one into the other and they will have the same callback.

Alternately, you can make them have a completely different callback by specifying your own value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM