Call method from another GUI

조회 수: 13 (최근 30일)
Ryan Sinfield
Ryan Sinfield 2016년 11월 18일
댓글: Ryan Sinfield 2016년 11월 18일
I have two GUIs, GUI1 and GUI2. Before I close GUI2 completely, I want to call a function from GUI1.
% In GUI2
gui1 = findobj('Tag', 'GUI1');
gui1.callThisBeforeClosingFcn();
close(handles.GUI2);
I get an error when trying to call the GUI1 function - "No appropriate method, propery, or field 'callThisBeforeClosingFcn' for class matlab.ui.Figure."
What is the correct way to call that function?

답변 (1개)

Jan
Jan 2016년 11월 18일
편집: Jan 2016년 11월 18일
I cannot guess, what "gui1.callThisBeforeClosingFcn()" should be. Perhaops you want to call a function before closing the figure autoamtically? But what might "from another GUI" mean then...
figure('CloseRequestFcn', @callThisBeforeClosingFcn, ...
'DeleteFcn', @callThisBeforeClosingFcn);
and your function:
function callThisBeforeClosingFcn(FigH, EventData)
handles = guidata(FigH);
... do whatever you want
figure('CloseRequestFcn', [], ...
'DeleteFcn', []);
delete(figure);
Now simply close or delete the figure, or close it using the "x" in the window border and the specified function is called automatically.
  댓글 수: 2
Ryan Sinfield
Ryan Sinfield 2016년 11월 18일
The function I want to call is from another GUI's m file. I have GUI2.m, from which I need to call the function callThisBeforeClosingFcn that is located in GUI1.m. Does this help clarify?
Ryan Sinfield
Ryan Sinfield 2016년 11월 18일
In other words - I want to call a method from another m file. How can I do that?

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

카테고리

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