Creating GUI using MATLAB guide command

12 views (last 30 days)
Junho
Junho on 8 Apr 2015
Answered: Geoff Hayes on 11 Apr 2015
Hello, I'm struggling about making GUI with 'guide' command in MATLAB 2015 version
Especially where I'm stuck with is the usage or definition of eventdata when you create any buttons on GUI
for example, if you plot a pushbutton on GUI panel it gives you like
%%
function pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
From my knowledge, handles have any information for button's feature like font, back ground color etc and
hObject stores every handles that you make. However, I really have no idea what eventdata is.
it shows eventdata will be on service after future version but I like to know any method to handle that

Answers (1)

Geoff Hayes
Geoff Hayes on 11 Apr 2015
Junho - I think that you can safely ignore the eventdata parameter for callbacks of this type. If you have a key press callback for your GUI/figure with the function signature
function figure1_KeyPressFcn(hObject, eventdata, handles)
then, when this function is called after the user has pressed a keyboard key, keydata would be something similar to
eventdata =
Character: 'k'
Modifier: {1x0 cell}
Key: 'k'
Note that you say that handles have any information for button's feature like font, back ground color etc. This is almost correct. The handles structure has handles to all GUI elements/controls that you have created using GUIDE. So it will have the handle to your pusbutton1, axes1, etc. This allows you to reference the other controls in your GUI when, for example, the push button is pressed and its pushbutton_Callback fires. You could then get the state of any radio button or contents of any edit text field is, or you could set these other controls with new/updated data.
You can also update the handles structure with user-defined data. This is useful if you have one callback load a file and you want to save the file or its contents so that when the user presses another button, its callback will have access to that file or contents (allows you to avoid the use of global parameters). See guidata for examples of how you would do this.
hObject is just the handle to the GUI control that the callback is associated with. For example, in the callback
function pushbutton_Callback(hObject, eventdata, handles)
hObject is the handle to the pushbutton and is identical to handles.pushbutton.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!