フィルターのクリア

Difference between setappdata and guidata?

1 回表示 (過去 30 日間)
B_Richardson
B_Richardson 2011 年 7 月 14 日
Hello everyone,
I have a quick question: What is the difference between setappdata and guidata functions? In what situation is one more appropriate to use than the other? And also if possible, can someone provide an example of both in use?
I have read the matlab help description and it seems that they can be used interchangeably?

採用された回答

Walter Roberson
Walter Roberson 2011 年 7 月 14 日
guidata() is a wrapper around getappdata() and setappdata(), using the specific property name UsedByGUIData_m
guidata() was designed for use with GUIDE but can be used more generally.
guidata() is handy for treating the data as a group (such as for clearing it all prior to saving a figure), and is also handy for reducing the number of calls one might otherwise make to [gs]etappdata() if one is working with more than one property.
Some people prefer to separate the graphic object handles from the data or control variables; people who use guidata() tend to merge those together (and then tend to get confused about whether a particular name is the name of a handle or the name of an array or structure.)

その他の回答 (1 件)

Doug Eastman
Doug Eastman 2011 年 7 月 14 日
You can look at the code for GUIDATA by typing
edit guidata
You'll notice that GUIDATA calls SETAPPDATA, it just provides some additional layers on top of it. Mainly it allows you to pass in the handle to any element in a figure and it also uses a hard-coded property name 'UsedByGUIData_m' that is removed before the figure is saved.
I would say in general if you are building GUIs especially created by GUIDE, you should be using GUIDATA, but if you are doing something more advanced and want to add your own arbitrary properties, you would use SETAPPDATA.
  8 件のコメント
Walter Roberson
Walter Roberson 2011 年 7 月 15 日
Remember where I wrote above that, "people who use guidata() tend to merge those together (and then tend to get confused about whether a particular name is the name of a handle or the name of an array or structure.)"
Your handles.A is, despite its name, not a handle; if you had used setappdata() instead of guidata() you would have been more likely to keep the data types straight.
To unconditionally update A in a callback, you would use code like I showed above,
handles.A = zeros(10,length(get(handles.listbox3,'string')));
guidata(gcf, handles);
B_Richardson
B_Richardson 2011 年 7 月 15 日
I see! Thank you!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by