フィルターのクリア

How to use guidata to save data in external MATLAB function?

1 回表示 (過去 30 日間)
rbme17
rbme17 2017 年 8 月 1 日
編集済み: rbme17 2017 年 8 月 2 日
Hi all,
I'm writing a GUI that uses external function m files. I call handles into the function to use values in a for loop. I eventually want to overwrite handles with the new value found from the for loop.
e.g.
handles.struct.variable = 0; % initialized in GUI main code
___________________________________________________________
for x = 1:100
variable = handles.struct.variable(x)
variable = some equation/code;
handles.struct.variable(x) = variable
guidata(hObject, handles) %<--------- this is my issue
end
I pre-allocated the structure I'm using, but when I try to save the data using 'guidata(hObject, handles) I get an error:
"Undefined function or variable 'hObject'."
Does anyone know a way to save the data to handles in a function file written outside of the GUI?
Thanks!

採用された回答

Walter Roberson
Walter Roberson 2017 年 8 月 1 日
To use guidata to update the master copy of the handles, you need to know at least one graphics object that is part of the figure that has the guidata attached to it. It can be anything inside the figure -- a uicontrol, an axes, a line, a context menu, anything. Perhaps you have an appropriate object inside the handles structure already.
If not, then you can use findobj(), provided you know something unique about some object that is inside the figure. You can findobj() to locate all figures, but if you don't know something about the one acting as your GUI then you might accidentally end up with multiple figures and pick the wrong one.
  3 件のコメント
Walter Roberson
Walter Roberson 2017 年 8 月 2 日
Try
guidata(handles.pushbutton2, handles)
rbme17
rbme17 2017 年 8 月 2 日
編集済み: rbme17 2017 年 8 月 2 日
Whoops! Seems to work fine now, thanks Walter!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by