Why when using 'setappdata' in Appdesigner do I have to store it in a figure? Can I store it someplace else?

10 ビュー (過去 30 日間)
AThomas
AThomas 2020 年 4 月 28 日
回答済み: Rik 2020 年 4 月 28 日
In appdesigner, when trying to share variables among callbacks I supposedly have to use 'setappdata', however the documentation isn't very clear and I can't understand the full purpose of storing it in a 'figure'.
When I run the code I have a figure window pop up that I don't want.
Can someone please explain the 'setappdata' function to me simply?
  1 件のコメント
AThomas
AThomas 2020 年 4 月 28 日
So I've stored the 'appdata' into a graphics object, but now when trying to call it within a callback its now saying its an unrecognised ...

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

回答 (1 件)

Rik
Rik 2020 年 4 月 28 日
With the setappdata you are storing data somewhere in RAM, linking it to a graphics object.
f=uifigure;
setappdata(f,'foo','bar')%use a handle to your uifigure, not figure
getappdata(f,'foo')
Every time you (re)create the graphics objects the appdata starts out empty. If you try to retrieve a nonexistent Name, you will either get an error (as the doc seems to suggest), or an empty array (as my copy of R2019a does).
The purpose is to have specific properties stored with the graphics object they are connected with. That means you can store data separately for each axes in your GUI, or for separate instances of your GUI.

カテゴリ

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