
一、gca、gcf、gco
1、三者的功能定义:
gcf 返回当前Figure 对象的句柄值
gca 返回当前axes 对象的句柄值
gco 返回当前鼠标单击的句柄值,该对象可以是除root 对象外的任意图形对象,并且Matlab 会把当前图形对象的句柄值存放在Figure 的CurrentObject属性中。
2.matlab下的图形对象
clear all
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
二、对象基础操作及概念
clear all
plot([0:10])
title('示例')
allchild(gcf)%获取当前图的子对象
get(gcf)
get(gca)
set(gca(1),'Position',[0.1300 0.1100 0.5 0.5],'color',[0 1 0])
三、
clear all
%创建axes坐标图
h = axes();
%定义图形位置和大小,[left bottom width height]
set(h,'Position',[0.1 0.1 0.8 0.8]);
%画图
x=0:0.01:12;
y=sin(x);
plot(h,sin(x));
%Sets the location of the tick marks along the axis
set(h,'XTickLabel',[0;2;4;6;8;10;12;14]);
%显示方格
set(h,'XGrid','on','YGrid','on');
%设置颜色、字体等属性
set(h,'XColor',[0 0 0.7],...
'YColor',[0.7 0 0.7],...
'Color',[.9 .5 .9],...
'GridLineStyle','--',...
'FontName','times',...
'FontAngle','italic',...
'FontSize',14);
%定义X坐标和Y坐标的标签名
set(get(h,'XLabel'),'String','Values of X',...
'FontName','times',...
'FontAngle','italic',...
'FontSize',14);
set(get(h,'YLabel'),'String','Values of Y',...
'FontName','times',...
'FontAngle','italic',...
'FontSize',14)
%定义图形标题名
set(get(h,'Title'),'String','y=sin(x)',...
'FontName','times',...
'Color',[0 0 0.7],...
'FontSize',14);