Changlng a handles.variable size

조회 수: 4 (최근 30일)
Bill Saidel
Bill Saidel 2015년 7월 17일
답변: Steven Lord 2015년 7월 17일
Is the size of a handles variable (ex., handles.data) fixed or can it be incremented? In my script, the handles.data changes its value with each listener update but does not increment as expected with vertcat. However, using a global variable instead, the global variable does increment as expected.

답변 (2개)

Walter Roberson
Walter Roberson 2015년 7월 17일
The sizes are definitely not fixed. However, be sure to use guidata() to update the "master" copy of the handles structure
function DoSomething(hObject, event, handles)
...
handles.somevariable = rand(5,10);
...
guidata(hObject, handles); %update master copy
end

Steven Lord
Steven Lord 2015년 7월 17일
I'm assuming this is in the context of a GUI from the fact that you're referring to a handles structure. If you defined your listener function like:
addlistener(source, event, @(varargin) mycallback(handles))
then changes to the "master copy" of the handles structure associated with the GUI will NOT affect the COPY of the handles structure created when that anonymous function was created. If you want to do that, I would suggest passing in something that's not going to change (like the handle of your GUI's main figure window) and using that handle and GUIDATA retrieving a copy of the current master handles structure inside the callback.

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by