saving new handles in callback using guidata

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

Risposte (1)

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".

Richiesto:

il 17 Apr 2012

Community Treasure Hunt

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

Start Hunting!

Translated by