saving new handles in callback using guidata

조회 수: 7 (최근 30일)
QuocBao Vu
QuocBao Vu 2012년 4월 17일
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에서 Model, Block, and Port Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by