필터 지우기
필터 지우기

Grab and reference data from OpeningFcn?

조회 수: 1 (최근 30일)
rbme17
rbme17 2017년 7월 17일
댓글: rbme17 2017년 7월 17일
Hi,
I was wondering if there's a way to call data from OpeningFcn in a Matlab GUI. I need to reference an initialized value in OpeningFcn to one that's updated with the user input once a pushbutton is pressed.
The initialized data (xi) is compared to the user's gui input _(xgui). If they're not equal, an if statement will run.
if xi ~= xgui
xi = xgui
for ...
...(some other code)...
end
end
I've tried creating variables and structures in OpeningFcn, referencing it using handles.OpeningFcn, but I can't seem to figure it out. Can someone please help?
Thanks!

채택된 답변

Geoff Hayes
Geoff Hayes 2017년 7월 17일
rtbme17 - if you have (for example) variables in your OpeningFcn that you want to reference later, then save them to the handles structure. For example,
function GUI_OpeningFcn(hObject, eventdata, handles, varargin)
% do some stuff
x = 42;
% save x to the handles structure
handles.x = x;
guidata(hObject, handles);
Note that the guidata(hObject, handles); is important as it will save the updated handles structure so that all other callbacks have access to this updated structure (and so can access x). Then in some callback you would do
function pushbutton1_Callback(hObject, eventdata, handles)
% use x
if isfield(handles, 'x')
y = handles.x * 2;
% etc.
end
In the above, we check to see if x is a fields within handles before trying to use it.
  댓글 수: 1
rbme17
rbme17 2017년 7월 17일
That was super helpful, thanks so much!

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

추가 답변 (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