如何关闭指定的 MATLAB 图像

How to close a specified MATLAB image

在MATLAB 中使用了一段时间的一些基本图像处理后,问这个简单的问题让我感到有点尴尬...为什么以下代码的最后一条语句无法关闭指定的图像?在 MATLAB 中关闭指定图像的正确方法是什么?

clear; clc; close all; 
% 

%% Identify available webcams.  
% The MATLAB Webcam Supoort Package must be installed first.  
myWebcams = webcamlist      % Identifies available webcams.
cam = webcam(myWebcams{1})  % Identifies the current webcam.
% 

%% Acquire webcam images. 
preview(cam)                                % A preview of the img.  
img = snapshot(cam); img = rgb2gray(img);   % A single webcam img.  
imgh = imshow(img);                         % Display the img.
[imgHeight, imgWidth] = size(img)
close(imgh)

使用

close(imgh)

我收到以下错误:

>> close(imgh)
Error using close (line 116)
Invalid figure handle.

这里imgh不是数字句柄。它是图像对象的句柄,该图像对象位于坐标区对象内,坐标区对象位于图形内。要关闭图形,请使用

>> close(imgh.Parent.Parent);

或者,如果您使用旧版本的 MATLAB,请使用

>> close(get(get(h, 'Parent'), 'Parent'));

或者,更简单地说,使用

>> close all