Changlng a handles.variable size

1 view (last 30 days)
Bill Saidel
Bill Saidel on 17 Jul 2015
Answered: Steven Lord on 17 Jul 2015
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.

Answers (2)

Walter Roberson
Walter Roberson on 17 Jul 2015
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 on 17 Jul 2015
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.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!