Issues with callbacks and large handle structures?

조회 수: 1 (최근 30일)
Sean
Sean 2011년 11월 14일
I am working on a gui, and encountered a strange problem. When I pass 'h' to a uicontrol callback and put a breakpoint in the callback, I find that only the first 30 handles are present in the callback instance of 'h'. (i.e. h.figure, h.CCUpanel, h.gammacontrol, etc.)
Since the callback was called by a later uicontrol, errors were generated when I attempted to refer to it.
Has anyone seen this before and/or know how to correct it or work around it?
Thanks, Sean
  댓글 수: 4
Image Analyst
Image Analyst 2011년 11월 15일
Perhaps you're only seeing part of it in the popup window when you hover over it but if you type handles into the command window or look at it in the variable editor you will see the rest of the members. Is that a possibility? Either that or like the others said you added members to handles but didn't do anything to make sure those additions are kept around for the next function that expects to see them.
Sean
Sean 2011년 11월 15일
Thank you all...
Jan is correct. Apparently I am only passing a partial handle struct to the callback. I didn't realize that it hardened the input variables when the callback was set (as opposed to sending the designated variables at time of activation).
Jan... If you formally answer, I will accept it.
Also, does anyone know how to set a pointer to the handle structure as an input to a callback (so that a dynamic structure can be used)?
Thanks,
Sean

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2011년 11월 15일
It is impossible to know the reason without seeing the code. Perhaps you have defined the callback function such, that it contains the only partially created handles struct? Then using the function GUIDATA is equivalent to using a pointer to the handles struct:
% Create the figure and the handles struct:
handles.DlgH = figure;
% Pass an incomplete handles struct:
uicontrol('Style', 'pushbutton', 'Callback', {@Callback, handles});
% Callback function:
function Callback(ObjH, EventData, handles) % handles is incomplete!
handles = guidata(handles.DlgH); % handles is complete and uptodate
...
handles.MyData = clock;
guidata(handles);
I'd prefer the following to avoid using the incomplet handles struct:
... 'Callback', {@Callback, DlgH}
...
function Callback(ObjH, EventData, DlgH)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by