Академический Документы
Профессиональный Документы
Культура Документы
Handles Graphics
Handles Graphics
Handle Graphics refers to a system of
graphics objects that MATLAB uses to implement
graphing and visualization functions.
Each object created has a fixed set of
properties. These properties can be to control the
behavior and appearance of the graph.
When call a plotting function, MATLAB
creates the graph using various graphics objects,
such as a figure window, axes, lines, text, and so
on.
MATLAB enables to query the value of each
property and set the values of most properties.
2
9.1 The Graphics System
The MATLAB graphics system is based on a
hierarchical system of graphics objects, each of which
is known by a unique name called a handle.
3
9.2 Object Handles
Hndl=figure;
gcf; gca;
4
9.2 Object Handles
>> plot(1,2)
>> h=gcf
h=
1
>> h=gca
h=
151.0012
>> get(gcf,'CurrentAxes')
ans =
151.0012
>>
5
9.3 Examining and Changing
Object Properties
9.3.1 Changing Object Properties
at Creation Time
>> x=[1,2,3]
x=
1 2 3
>> y=[4 5 6]
y=
4 5 6
>> plot(x,y,'LineWidth',2)
>> plot(x,y,'LineWidth',5)
6
9.3.2 Changing Object Properties
after Creation Time
value=get(handle,’PropertyName’);
value=get(handle);
>> get(0,'DefaultLineLineWidth')
ans =
0.5000
7
9.3.2 Changing Object Properties
after Creation Time
set(handle,'PropertyName1',
PropertyValue1,...)
>> plot(peaks)
>> set(findobj('Type','line'),'Color','k')
>> h=plot(peaks)
>> set(h,'Color','k')
>> h=plot(1,2)
>> result=get(h) 8
9.3.2 Changing Object Properties
after Creation Time
x=0:0.1:2;
y=x.^2;
h=plot(x,y);
Result=get(h);
set(h,'LineWidth',8,'LineStyle','--')
9
9.3.2 Changing Object Properties
after Creation Time
figure(2)
x=0:0.1:2;
y=1./(x.^2);
h=plot(x,y);
grid on;
propedit(h);
10
9.4 Using set to List Possible
Property Values
>> h=plot(1,1)
h=
3.0048
>> set(h,'LineStyle')
[ {-} | -- | : | -. | none ]
>> set(h,'LineWidth')
A line's "LineWidth" property does not have
a fixed set of property values.
>> set(h)
11
9.4 Using set to List Possible
Property Values
% plotsinc.m
12
9.6 Finding Objects
gcf Returns the handle of the
current figure;
gca Returns the handle of the
current axes in the current figure;
gco Returns the handle of the
object;
findobj Finds a graphics object with a
specified property value;
13
9.7 Selecting Objects with
the mouse
% select_object.m
plot of sin x and cos x
1
sine
0.8 cosine
0.6
0.4
sin x and cos x
0.2
-0.2
-0.4
-0.6
-0.8
-1
-10 -8 -6 -4 -2 0 2 4 6 8 10
x 14
9.8 Position and Units
% position_object.m
plot of cos x
1
0.5
cos x
0
Test string 2
-1
0.5 -5 0 5
x
sin x
0 sin(x)
-0.5
15
-1
-5 0 5
x