打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Purpose of guidata(hObject,handles)

Every graphics "object" (a figure, an axes, a button, a textbox etc) is represented by a "handle" variable. That's the hObject.

If you're making a GUI, you actually want to store data about the "state" of the program inside the GUI somewhere. Think of a GUI with 2 buttons (one with a "+", one with a "-") and a text display that starts at "1". If the user clicks the +, that display should increment. If the user clicks the "-" that display should decrement.

Somewhere in the GUI, a "counter" variable needs to be stored. One way of doing it is storing it in the "guidata" of your figure's GUI. That's a special location specifically for GUIs. I think that there are two reasons why it's special:

  1. Every hObject (a pushbutton, an axes, etc) that is a child of the same figure points to the same "guidata". So it's a common place for all parts of a GUI to share data.
  2. Any callback function in the GUI automatically gets the guidata as its third argument. That is, whenever you click a button of a GUI with some guidata set, the input parameters (by default) is always a copy of guidata(GUIhandle), made immediately at the time of clicking the button.

So a callback function will look like:

function pushButtonCallback(buttonHandle, eventData, handles)...disp(handles)

Now, handles is just a structure, so let's say that we've stored the counter that we're using inhandles.counter. In other words, somewhere at the start of your GUI you had lines like:

handles = guidata(hObject);handles.counter = 1;guidata(hObject, handles);

When they hit the "+" button, we want to increment handles.counterbut we also want this new value available to every other callback. To do that, we need to update the handles.counter field, and then puthandles back into the GUIs guidata. As soon as we've done that, the next time the user clicks a button, they'll be using the newly updated version of handles.

function plusPushButtonCallback(buttonHandle, eventData, handles)
% At THIS point, "handles" is just a copy of guidata for the GUIhandles.counter = handles.counter + 1;% At THIS point, "handles" is different to the guidata for the GUIguidata(buttonHandle, handles);% At THIS point, "handles" has been put back in as new guidata for the GUI

Did that make things a little clearer Amanda?



=========================================================================

The guidata is stored in the figure object that is the ancestor of whatever you pass in to guidata()



===========================================================================

This stores the variable named 'handles' in the guidata of the object with handle HObject.

I assume you saw this in the Openfcn of a GUIDE GUI, correct? If so, then this line is simply storing a structure called 'handles', which contains the handles to all visible graphics objects, in the guidata of the figure. From anywhere else you can access this structure by calling GUIDATA(hfig). For example, say you have a GUIDE GUI named mygui. Do this at the command line:

H = mygui;  % Returns the handle of the figure into H.guidata(H)
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Matlab:MATLAB GUI不同控件函数间变量传递的三种方法详解
阿英讲多个matlab gui之间的数据传递
MATLAB实现GUI界面
Facebook’s New Realtime Analytics System
利用Matlab提取图片中曲线数据
【GUI应用】Matlab实现矩阵计算器
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服