function h=gcf()
% GCF Get current figure handle.
% H=GCF returns the handle to the current figure.The current fugure is the figure(graphics window)that graphics commands like PLOT,TITLE,SURF,etc.draw to
if
issued.
%
% Use the commands FIGURE to change the current figure to a diffent figure,or to create
new
% ones.
%
% See also FIGURE,CLOSE,CLF,GCA.
% Copyright (c)
1984
-
94
by The MathWorks,Inc.
h=get(
0
,
'CurrentFigure'
);
<br>类似的,函数gca 返回当前图形的
'CurrentAxes'
属性值,它的M 文件描
述如下。
<br>function h=gca()
% GCA Get current axis handle.
% H=GCA returns the handle to the current axis.The current axis is the axis that graphics % command like PLOT,TITLE,SURF,etc.draw to
if
issued.
%
% Use the commands AXES or SUBPLOT to change the current axis to a different axis,or to % create
new
ones.
% see also AXES,SUBPLOT,DELETE,CLA,HOLD,GCF.
% Copyright (c)
1984
-
94
by The MathWorks,Inc.h=get(get(
0
,
'CurrentFigure'
),
'CurrentAxes'
);
<br>函数gco 也相同,只是它在试图获得当前对象之前先检查图形是否存在。注意函数gcf 和gca 能促使建立相关的对象,如果它们不存在的话。如下所示的函数gco,它先检查子对象(
'Children'
)是否存在,如果不存在,就不创建图形对象。
<br>function object=gco(figure)
<br>%GCO Handle of current object.
% OBJECT=GCO returns the current object in the current figure.
%
% OBJECT=GCO(FIGURE) returns the current object in figure FIGURE.
%
% The current object
for
a given figure is the last object clicked on with mouse.
%Copyright (c)
1984
-
94
by The MathWorks,Inc.
<br>
if
isempty(get(
0
,
'Children'
))
object=[ ];
return
;
end;
if
(nargin==
0
)
figure=get(
0
,
'CurrentFigure'
);
end
object=get(figure,
'CurrentObject'
);
当需要一些除了
'CurrentFigure'
、
'CurrentAxes'
和
'CurrentObject'
之外的某些东西时,可以用函数get 来获得一个对象的子对象的句柄向量。例如:
Hx_kids=get(gcf,
'Children'
)返回一个向量,它包含当前图形子对象的句柄。
可以用获得子对象
'Children'
句柄的技术彻底搜索句柄图形的层次结构中来找到所要的对象。例如,在画出一些数据后,寻找绿色线条句柄的问题。
x=-pi:pi/
20
:pi; % create some data
y=sin(x);
z=cos(x);
plot(x,y,
'r'
,x,z,
'g'
); % plot two lines in red and green
Hl_lines=get(gca,
'Children'
); % get the line handles
for
k=
1
:size(Hl_lines) % find the green line
if
get(Hl_lines(k),
'Color'
)==[
0
1
0
]
Hl_green=Hl_lines(k)
end
end
Hl_green=
58.0001