Manually programmed GUI, guidata() not updating the handles struct

조회 수: 1 (최근 30일)
Benjamin Sorel
Benjamin Sorel 2022년 8월 15일
답변: Rik 2022년 8월 16일
The basic structure of my GUI is a figure with multiple tabs. Each tab is a panel with its own children buttons and other uicontrols. In one of the panels, i have a PushButton with a callback to a function that counts the amount of checkboxes selected on a different panel. My main handle structure is called 'TabHandles', where i store the overall figure object, each panel object, and other things. The pushbutton is coded as follows:
numberEventsButton = uicontrol('Parent',TabHandles(NumberOfTabs).TabPanel,'Style','PushButton',...
'String','# of Events Currently Selected (Push)','Callback',{@currentSelectionCounter});
The callback function is:
function currentSelectionCounter(~,~)
TabHandles = guidata(gcf);
totEvents = TabHandles(1).Counter;
TabHandles(2).Counter = 0;
for k=1:totEvents
newHandles(2).Counter = newHandles(2).Counter + get(newHandles(k).EventCheckbox,'Value');
end
guidata(gcf,TabHandles)
end
Using the debugger, the new local version of 'TabHandles' created in the callback function does indeed have the correct new value I'd like to pass to the main GUI handles sturct (which is TabHandles(2).Counter) , but after using guidata(gcf,TabHandles) the handles structure in the main GUI workspace does not update. I use guidata(gcf) to get the lastest copy of the TabHandles struct, and i then use guidata() with the 2 inputs to, in theory, save my new modified TabHandles back to the maimn figure. What am I doing wrong? Is there an issue with the PushButton being a child component of a panel, which is itself a child component of the figure? Been scratching my head for a while now
  댓글 수: 2
Rik
Rik 2022년 8월 16일
Did you reload the struct from guidata after editing it in this subfunction?
Benjamin Sorel
Benjamin Sorel 2022년 8월 16일
I think that's my issue...im not sure how or where to do that. After looking throught the debugger more, I found that the handles struct in fact WAS updating in real time, but when I would cancel the gui and look in the workspace, the struct wouldnt be updated.
How do I reload the struct after editing it?

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

채택된 답변

Rik
Rik 2022년 8월 16일
The guidata struct is not a global variable. You should treat it as a mat file. When you write to it, other functions need to reload it to apply the changes.
So at any point where you expect changes to occur, make sure you reload the guidata struct.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by