필터 지우기
필터 지우기

How to close a figure made in one function, from a different function

조회 수: 2 (최근 30일)
Bradley
Bradley 2024년 3월 28일
편집: Matt J 2024년 3월 31일
Im making a program that graphs data and several buttons. One button plots graph A and another button plots graph B. When I click the button that graphs plot B I want plot A to close and plot B to open, I added close(ax) to function B but I get an error that the variable ax doesnt exist. How do I define ax in function B so that I can close Plot A before plot B pops up? Thanks!

채택된 답변

Matt J
Matt J 2024년 3월 28일
편집: Matt J 2024년 3월 28일
How do I define ax in function B so that I can close Plot A
You don't. You create ax in function A (it is obtained from the plotting command that creates the graph), save it somewhere, and pass it to function B when it is needed there.
If this were being done in appdesigner, it would be a routine matter to save ax to a property of the app object, which gets passed around automatically to all the button callbacks in the app.
  댓글 수: 2
Bradley
Bradley 2024년 3월 31일
Im creating a ui progammatically, and ive been trying to figure out a way to pass this plot from one function to another, would you happen to have an example I could look at? Thanks!
Matt J
Matt J 2024년 3월 31일
편집: Matt J 2024년 3월 31일
Hf=createPlot(1:5,rand(1,5));
closePlot(Hf);
function fig=createPlot(x,y)
fig=ancestor(plot(x,y),'figure');
end
function closePlot(fig)
close(fig)
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by