Update the GUI handles structure from inside a callback function

4 ビュー (過去 30 日間)
JM
JM 2012 年 7 月 12 日
This seems like such a basic problem that there must be an easy solution to it, but I'm new to Matlab and can't figure it out...
I have a GUIDE gui with an axes and draggable points, and whenever a point is moved I need a callback function to make changes to something in the handles structure. I can add a callback function using addNewPositionCallback(), but then the callback function can't see and make changes to outside variables. Therefore, I can't make changes to handles from inside the callback function.
I thought of passing the handles structure to the callback and returning the updated structure as an output... but the callback function apparently can't have any outputs!
Do I make the handles structure global? I don't think that's a good idea though.
Thanks for any help!

回答 (1 件)

Kevin Claytor
Kevin Claytor 2012 年 7 月 12 日
After you make your changes to handles you have to update it with GUIDATA;
function my_Callback(hObject, eventdata, handles)
handles.somethingnew = 5;
% Store the value
guidata(hObject,handles);
  1 件のコメント
JM
JM 2012 年 7 月 25 日
That's what I would do, but it looks like the callback function can only take one input, the current position of the point. Am I reading this right? http://www.mathworks.com/help/toolbox/images/ref/imroi.html#addnewposcbk

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

カテゴリ

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