How do I create a button in a pop up that will allow a user to close all figures?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
I have a simulation tools which calls MATLAB functions. These functions produce many plots. The simulation will not stop until I close all the figures.
Is there a way to add a command in a pop up with a button asking the user if he want to close all the figures? I would like yes/no buttons with all figures closing when the user answers yes.
채택된 답변
choice = questdlg('Would you like to close all figures', ...
'Close figures', ...
'Yes','No','No');
switch choice
case 'Yes'
disp('All figures closed')
close all
case 'No'
disp('No figures closed')
end
댓글 수: 12
Of course, that would close any figures not opened by the tool as well.
In that case the OP needs to tag the figures or just give them specific names so he/she can know what figures should be closed
Here's how to tag figures
set(figurehandle,'Tag','myguifigure')
and how to close all figures with that specific tag
close(findobj('type','figure','tag','myguifigure'))
Thank you soooo much Paulo :) i have tried the first code and it works fine :) :)
with 'tag' it didn't work with me,I guess I did it the wrong way!
for testing,i create a figure, then i set the property 'tag' as u've mentioned,then if i use findobj,
findobj('type','figure','tag','myguifigure')
Empty matrix: 0-by-1
which is mean object not found?!
findobj('type','figure')
ans = 1
findobj('tag','myguifigure')
ans =171.0059
do i have to edit any other property to make it works?
It's working fine here but you can use:
close(findobj('tag','myguifigure'))
It will search all objects but the only ones with the tag will be the ones you want to close so it will work the same way.
Thank you Paulo for ur reply
i have tried
close(findobj('tag','myguifigure'))
but it give me following error:
Invalid figure handle.
Any idea? :(
I'm just guessing but it seems that you didn't tagged the figures properly, you tagged axes instead of figures.
this is my code actually:
x= -2*pi :1/5:2*pi;
y=sin(x);
h1=plot(x,y);
set(h1,'tag','myguifigure');
close(findobj('type','figuers','tag','myguifigure'))
get (h1)
-----------------
after executing,the figure still open!
and this is the object property:
DisplayName: ''
Annotation: [1x1 hg.Annotation]
Color: [0 0 1]
LineStyle: '-'
LineWidth: 0.5000
Marker: 'none'
MarkerSize: 6
MarkerEdgeColor: 'auto'
MarkerFaceColor: 'none'
XData: [1x63 double]
YData: [1x63 double]
ZData: [1x0 double]
BeingDeleted: 'off'
ButtonDownFcn: []
Children: [0x1 double]
Clipping: 'on'
CreateFcn: []
DeleteFcn: []
BusyAction: 'queue'
HandleVisibility: 'on'
HitTest: 'on'
Interruptible: 'on'
Selected: 'off'
SelectionHighlight: 'on'
Tag: 'myguifigure'
Type: 'line'
UIContextMenu: []
UserData: []
Visible: 'on'
Parent: 170.0105
XDataMode: 'manual'
XDataSource: ''
YDataSource: ''
ZDataSource: ''
get(h1,'Type') %h1 isn't the figure handle
Here's an hint about the problem
get(h1,'Type') %ans is line
b=get(h1,'Parent');
get(b,'Type') %ans is axes (line inside axes)
c=get(b,'Parent');
get(c,'Type')
%now you get the handle for the figure
when you plot using the plot function matlab creates a figure with an axes inside, you can create that figure and axes yourself
MyFigHandle=figure;
MyAxesHandle=axes;
set(MyFigHandle,'CurrentAxes',MyAxesHandle);
set(MyFigHandle,'tag','myguifigure');
Aha!Ok everything is clear now
Thank you so much for all your help I really appreciate it.
If you're looking for the handle of the figure that is the parent of object h, consider the |ancestor| function:
f = ancestor(h,'figure','toplevel');
Cheers,
Brett
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
제품
참고 항목
2011년 2월 7일
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
