saving new handles in callback using guidata

1 次查看(过去 30 天)
Hello
I have a problem of saving handles I created in my callback function and updating my main handle using guidata. Example of my code below. I'm doing this programmatically.
function myCallbackFunction(hObject, eventdata, handles, varargin)
myhandles = guidata(hObject);
%do something
myhandles.newHandle = [1 2 3 4]; %Make a new Handle
guidata(hObject, myhandles)
end
I didn't put everything the the example, but tried I created a new handle myhandles.newHandle which is and array. After updating everything using guidata, I check my main handle h in my main function there is no such handle h.newHandle. If built my gui using nested functions this problem doesn't occur only when I have all my functions setup as sub functions. Is the only solution to this problem is I have to create a handle h.newHandle in my main function and so when i call guidata(hObject) the handle is there for me to make changes

回答(1 个)

Walter Roberson
Walter Roberson 2012-4-17
In your main function you need to use
handles = guidata(gcf);
in order to update the main function's knowledge of the contents of "handles".

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by