I want to close the invisible figure in an app, but after I use command: close all hidden, the apps are becomes 'invalid or deleted objects'
close all hidden will only close figures including invisible figures, not apps. so...is there any mistake with my operation?
Thanks!
Yu

댓글 수: 8

Yu Li
Yu Li 2019년 1월 4일
no, it is at the beginning of a call back function in push-buttom in my app.
or try to delete the specific hidden figure in this way:
close(h)
name the figure as h, let see will it working fine or not.
Yu Li
Yu Li 2019년 1월 4일
the problem is that the name of figure handle is not clear, because it may be generated by some other function, it may be f1,f2,.....fn, or h1,h2....hn, etc.
Kevin Chng
Kevin Chng 2019년 1월 4일
편집: Kevin Chng 2019년 1월 4일
Try
figHandles = get(groot, 'Children');
for i=1:1:length(figHandles)
close(figHandles(i));
end
If error is persistent, i believe there is something still running with the figures.
Yu Li
Yu Li 2019년 1월 4일
Thanks for your reply.
first I restart my Matlab to ensure that there is no figure applied.
then, I type:
h=figure(5);
figHandles = get(groot, 'Children')
below are all properties of figHandles:
Alphamap: [1×64 double]
BeingDeleted: 'off'
BusyAction: 'queue'
ButtonDownFcn: ''
Children: [0×0 GraphicsPlaceholder]
Clipping: 'on'
CloseRequestFcn: 'closereq'
Color: [0.9400 0.9400 0.9400]
Colormap: [64×3 double]
CreateFcn: ''
CurrentAxes: [0×0 GraphicsPlaceholder]
CurrentCharacter: ''
CurrentObject: [0×0 GraphicsPlaceholder]
CurrentPoint: [0 0]
DeleteFcn: ''
DockControls: 'on'
FileName: ''
GraphicsSmoothing: 'on'
HandleVisibility: 'on'
InnerPosition: [680 558 560 420]
IntegerHandle: 'on'
Interruptible: 'on'
InvertHardcopy: 'on'
KeyPressFcn: ''
KeyReleaseFcn: ''
MenuBar: 'figure'
Name: ''
NextPlot: 'add'
Number: 5
NumberTitle: 'on'
OuterPosition: [672 550 576 513]
PaperOrientation: 'portrait'
PaperPosition: [1.3333 3.3125 5.8333 4.3750]
PaperPositionMode: 'auto'
PaperSize: [8.5000 11]
PaperType: 'usletter'
PaperUnits: 'inches'
Parent: [1×1 Root]
Pointer: 'arrow'
PointerShapeCData: [16×16 double]
PointerShapeHotSpot: [1 1]
Position: [680 558 560 420]
Renderer: 'opengl'
RendererMode: 'auto'
Resize: 'on'
SelectionType: 'normal'
SizeChangedFcn: ''
Tag: ''
ToolBar: 'auto'
Type: 'figure'
UIContextMenu: [0×0 GraphicsPlaceholder]
Units: 'pixels'
UserData: []
Visible: 'on'
WindowButtonDownFcn: ''
WindowButtonMotionFcn: ''
WindowButtonUpFcn: ''
WindowKeyPressFcn: ''
WindowKeyReleaseFcn: ''
WindowScrollWheelFcn: ''
WindowStyle: 'normal'
there is no handle name called 'h', so how can I close it?
Thanks!'
Yu
Stephen23
Stephen23 2019년 1월 7일
편집: Stephen23 2019년 1월 7일
"but according to this page: https://www.mathworks.com/help/matlab/ref/close.html close all hidden will only close figures including invisible figures, not apps"
I searched that page for the word "app" and it only occurs once in a link below the help itself. Why do you think that close does not apply to apps? I don't see that written anywhere on that page.
In any case, writing close all is a sledgehammer approach to writing code. While it might be fun and useful from the command line, coding something like that into any app, GUI, or function is like shooting yourself in the knee. Instead of writing such brutal, uncontrolled code, learn how to obtain and use explicit handles for all graphics objects that you use:
Once you learn to use graphics object handles then your code will be much more robust, reliable, and easier to debug.
Yu Li
Yu Li 2019년 1월 7일
Hi:
Please allow me some time to prepare a test app for you.
Thank you!
Yu

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

 채택된 답변

Luna
Luna 2019년 1월 4일

1 개 추천

Did you type those inside a function or in the command window?
h=figure(5);
figHandles = get(groot, 'Children')
For example,
h=figure(5);
figHandles = get(groot, 'Children');
clear h % clears the variable in the workspace
close(h) % h is deleted so it will obviously give an error.
close(figHandles) % figHandles is an instance of figure object. This should close your figure even if you deleted h from the workspace.
% be sure about which workspace you are working in.
If you create your figure in a function and if the function does not include any close action, after that function executed, you can't close it because your workspaces has changed from "function workspace" to "base workspace". If this is your case, add an output value to your function which is the handle of your figure object. (in here it is "h").
Check out below link:
Also that might be useful:
You should read more about handle classes to understand what happens when you create an instance of an object.
Here is the link:

댓글 수: 2

Yu Li
Yu Li 2019년 1월 7일
Thank you luna, I think this resolve my question.
Bests,
Yu
Luna
Luna 2019년 1월 11일
Your welcome ;) Please accept answer if it works.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

질문:

2019년 1월 4일

댓글:

2019년 1월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by