Sunday, June 19, 2011
example 4
this example plot 2 graphs in one figure and y-axis labeling is at both side of figure.
here is the code
function shili04
h0=figure('toolbar','none',...
'position',[200 150 450 250],...
'name','example4');
x=0:900;b=0.005;
y1=2*x;
y2=cos(b*x);
[h,~,~]=plotyy(x,y1,x,y2,'semilogy','plot');
axes(h(1))
ylabel('semilog plot');
axes(h(2))
ylabel('linear plot');
function shili04%function name shili04
h0=figure('toolbar','none',...
'position',[200 150 450 250],...
'name','example4');
x=0:900;b=0.005;%define constant; x is starting from 0 then increase 1 until 900; b is =0.005
y1=2*x;%y1 is equal to 2 multiply x
y2=cos(b*x);%y2 is b multiply x then cosine it
[h,~,~]=plotyy(x,y1,x,y2,'semilogy','plot');%main function that allow 2 kinds of y-axes labeling
here is some explanation found from matlab help file about plotyy
PLOTYY Graphs with y tick labels on the left and right
PLOTYY(X1,Y1,X2,Y2) plots Y1 versus X1 with y-axis labeling
on the left and plots Y2 versus X2 with y-axis labeling on
the right.
[AX,H1,H2] = PLOTYY(...) returns the handles of the two axes created in
AX and the handles of the graphics objects from each plot in H1
and H2. AX(1) is the left axes and AX(2) is the right axes.
axes(h(1))%handle the left axes
ylabel('semilog plot');%label the left axes semilog plot
axes(h(2))%handle the right axes
ylabel('linear plot');%label the right axes linear plot
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment