You are on page 1of 7

matlab

1.1
plot plot(x,y) x y
x y
1-1 0x2p y=2e-0.5xcos(4x)
x=0:pi/100:2*pi;y=2*exp(-0.5*x).*cos(4*pi*x);plot(x,y)
1-2
t=0:0.1:2*pi;x=t.*sin(3*t);y=t.*sin(t).*sin(t);plot(x,y);
plot plot(x)
x

1.2
1plot
(1) x y x
y x

(2) x,y x,y

(3) plot

2 plot plot(x1,y1,x2,y2,
,xn,yn)
(1) x1 y1x2 y2xn yn

(2) x,y

1-3 x1=linspace(0,2*pi,100);
x2=linspace(0,3*pi,100);
x3=linspace(0,4*pi,100);
y1=sin(x1);y2=1+sin(x2);
y3=2+sin(x3);x=[x1;x2;x3]';
y=[y1;y2;y3]';
plot(x,y,x1,y1-1)
3 MATLAB
plotyy
plotyy(x1,y1,x2,y2) x1,y1 x2,y2
x1,y1
x2,y2
1-4 y1=0.2e-0.5xcos(4x)
y2=2e-0.5xcos(x)
x=0:pi/100:2*pi;y1=0.2*exp(-0.5*x).*cos(4*pi*x);y2=2*exp(-
0.5*x).*cos(pi*x);plotyy(x,y1,x,y2);
4 hold on/off
hold
1-5 y1=0.2e-0.5xcos(4x)
y2=2e-0.5xcos(x) x=0:pi/100:2*pi;y1=0.2*exp(-
0.5*x).*cos(4*pi*x);plot(x,y1)hold ony2=2*exp(-
0.5*x).*cos(pi*x);plot(x,y2);hold off
1.3
MATLAB
b-.
y:d
MATLAB
plot
plot(x1,y1, 1,x2,y2, 2,,xn,yn, n)
1-6 y1=0.2e-
0.5xcos(4x) y2=2e-0.5xcos(x)
x=linspace(0,2*pi,1000);y1=0.2*exp(-0.5*x).*cos(4*pi*x);y2=2*exp(-
0.5*x).*cos(pi*x);k=find(abs(y1-y2)<1e-2); % y1 y2 (
) x1=x(k); % y1 y2 x y3=0.2*exp(-
0.5*x1).*cos(4*pi*x1); % y1 y2 y
plot(x,y1,x,y2,'k:',x1,y3,'bp');
1.4
1
title() xlabel(x )
ylabel(y ) text (x,y,) legend( 1, 2,)
ASCII LaTeX

text(0.3,0.5,sin({\omega}t+{\beta}))
sin(t+) 1-7 0x2p y1=2e-0.5x
y2=cos(4x)
x=0:pi/100:2*pi;y1=2*exp(-0.5*x);y2=cos(4*pi*x);plot(x,y1,x,y2)title('x
from 0 to 2{\pi}'); % xlabel('Variable X'); % X
ylabel('Variable Y'); % Y text(0.8,1.5,' y1=2e^{-0.5x}'); %
text(2.5,1.1,' y2=cos(4{\pi}x)');
legend(y1, y2) %
2
axis axis([xmin xmax ymin ymax zmin
zmax])axis axis equal
axis square()axis
autoaxis offaxis on
grid grid on/off
grid
box box on/off
box
1-8 3
t=0:0.01:2*pi;x=exp(i*t);y=[x;2*x;3*x]';plot(y)grid on; %
box on; % axis equal %
1.5
MATLAB 6.5

FileEditViewInsertToolsWindow Help 7
11
1.6
fplot fplot(fname,lims,tol,) fname
lims x,y tol
2e-3 plot
1-9 fplot f(x)=cos(tan(x))
fplot('cos(tan(pi*x))',[ 0,1],1e-4) 1.7
subplot subplot(m,n,p)
mn n m
p
5-10

2.1
1 MATLAB
semilogx(x1,y1, 1,x2,y2, 2,)
semilogy(x1,y1, 1,x2,y2, 2,) loglog(x1,y1, 1,x2,y2,
2,)
2 polar
polar(theta,rho,) theta rho
plot
1-12 r=sin(t)cos(t)
t=0:pi/50:2*pi;r=sin(t).*cos(t);polar(t,r,'-*');
2.2
MATLAB
bar(x,y,) stairs(x,y,
) stem(x,y,) fill(x1,y1, 1,x2,y2, 2,)
1-13
y=2sin(x)
x=0:pi/10:2*pi;y=2*sin(x);subplot(2,2,1);bar(x,y,'g');title('bar(x,y,''g'')');a
xis([0,7,-2,2]);subplot(2,2,2);stairs(x,y,'b');title('stairs(x,y,''b'')');axis([0,7,-
2,2]);subplot(2,2,3);stem(x,y,'k');title('stem(x,y,''k'')');axis([0,7,-
2,2]);subplot(2,2,4);fill(x,y,'y');title('fill(x,y,''y'')');axis([0,7,-2,2]);
MATLAB

1-14 (1) ()
2347,1827,2043,3025 (2)
7+2.9i 2-3i -1.5-6i
subplot(1,2,1);pie([2347,1827,2043,3025]);title(' '); legend('
','','',''); subplot(1,2,2);compass([7+2.9i,2-3i,-1.5-
6i]);title(''); MATLAB ezplot
(1) f = f(x)ezplot
ezplot(f)-2<x<2 f = f(x)
ezplot(f, [a,b]) a<x<b f = f(x) (2)
f = f(x,y)ezplot ezplot(f) -
2<x<2 -2<y<2 f(x,y) = 0 ezplot(f,
[xmin,xmax,ymin,ymax]) xmin<x<xmax ymin<y<ymax
f(x,y) = 0 ezplot(f, [a,b]) a<x<b a<y< b
f(x,y) = 0 (3) x = x(t) y = y(t)ezplot
ezplot(x,y) 0<t<2 x=x(t) y=y(t)
ezplot(x,y, [tmin,tmax]) tmin < t < tmax x=x(t)
y=y(t)
1-15
subplot(2,2,1);ezplot('x^2+y^2-9');axis
equalsubplot(2,2,2);ezplot('x^3+y^3-
5*x*y+1/5')subplot(2,2,3);ezplot('cos(tan(pi*x))',
[ 0,1])subplot(2,2,4);ezplot('8*cos(t)','4*sqrt(2)*sin(t)',[0,2*pi])

4.1
plot3 plot plot3(x1,y1,z1,
1,x2,y2,z2, 2,,xn,yn,zn, n) x,y,z
plot x,y,z
x,y,z x,y,z
x,y,z
1-16
t=0:pi/100:20*pi;x=sin(t);y=cos(t);z=t.*sin(t).*cos(t);plot3(x,y,z);title('Li
ne in 3-D Space');xlabel('X');ylabel('Y');zlabel('Z');grid on;
4.2
1 MATLAB meshgrid
x=a:d1:b; y=c:d2:d;
[X,Y]=meshgrid(x,y); X x
y Y y
x
2 surf mesh
mesh(x,y,z,c)surf(x,y,z,c)x,y,z x,y
z c

1-17 z=sin(x+sin(y))-x/10
[x,y]=meshgrid(0:0.25:4*pi);z=sin(x+sin(y))-x/10;mesh(x,y,z);axis([0
4*pi 0 4*pi -2.5 1]); meshc
meshz mesh
meshc xy z meshz
xy
1-18 xy [-8,8][-8,8] 4
[x,y]=meshgrid(-
8:0.5:8);z=sin(sqrt(x.^2+y.^2))./sqrt(x.^2+y.^2+eps);subplot(2,2,1);mesh(
x,y,z);title('mesh(x,y,z)')subplot(2,2,2);meshc(x,y,z);title('meshc(x,y,z)')su
bplot(2,2,3);meshz(x,y,z)title('meshz(x,y,z)')subplot(2,2,4);surf(x,y,z);title
('surf(x,y,z)')
3
sphere [x,y,z]=sphere(n)cylinder
[x,y,z]= cylinder(R,n)MATLAB peaks
<!--[if !supportEmptyParas]--> <!--
[endif]-->
1-19 t=0:pi/20:2*pi;[x,y,z]=
cylinder(2+sin(t),30);subplot(2,2,1);surf(x,y,z);subplot(2,2,2);
[x,y,z]=sphere;surf(x,y,z);subplot(2,1,2);[x,y,z]=peaks(30);
surf(x,y,z);<!--[if !supportEmptyParas]--> <!--[endif]-->
4.3

bar3stem3pie3
fill3 bar3 bar3(y)bar3(x,y)
stem3
stem3(z)stem3(x,y,z)pie3
pie3(x)fill3 fill
fill3(x,y,z,c)<!--[if !supportEmptyParas]-->
<!--[endif]-->
1-20 (1) (2)
y=2sin(x) (3) x=[2347,1827,2043,3025]
(4)
subplot(2,2,1);bar3(magic(4))subplot(2,2,2);y=2*sin(0:pi/10:2*pi);stem3(
y);subplot(2,2,3);pie3([2347,1827,2043,3025]);subplot(2,2,4);fill3(rand(3
,5),rand(3,5),rand(3,5), 'y' ) 1-21
subplot(1,2,1);
[X,Y,Z]=peaks(30);waterfall(X,Y,Z)xlabel('X-axis'),ylabel('Y-
axis'),zlabel('Z-axis');subplot(1,2,2);contour3(X,Y,Z,12,'k'); % 12
xlabel('X-axis'),ylabel('Y-axis'),zlabel('Z-axis');<!--[if !
supportEmptyParas]-->

5.1
MATLAB view view(az,el)
az el
-37.5, 30 5-22
5.2
1 MATLAB
3 [0,1]3
3 RGB <!--[if !
supportEmptyParas]--> <!--[endif]-->
2 (Color map) MATLAB MATLAB
m3
RGB
MATLAB
3
surf
shading shading faceted

shading flat

shading interp

1-23 3
[x,y,z]=sphere(20);colormap(copper);subplot(1,3,1);surf(x,y,z);axis
equalsubplot(1,3,2);surf(x,y,z);shading flat;axis
equalsubplot(1,3,3);surf(x,y,z);shading interp;axis equal
5.3
MATLAB light('Color',
1,'Style', 2,'Position', 3) <!--[if !supportEmptyParas]--> <!--
[endif]-->
5-24
[x,y,z]=sphere(20);subplot(1,2,1);surf(x,y,z);axis equal;light('Posi',
[0,1,1]);shading interp;hold on;plot3(0,1,1,'p');text(0,1,1,'
light');subplot(1,2,2);surf(x,y,z);axis equal;light('Posi',[1,0,1]);shading
interp;hold on;plot3(1,0,1,'p');text(1,0,1,' light');
5.4
5-25 x y
0 [x,y]=meshgrid(-
5:0.1:5);z=cos(x).*cos(y).*exp(-sqrt(x.^2+y.^2)/4);surf(x,y,z);shading
interp;pause %
i=find(x<=0&y<=0);z1=z;z1(i)=NaN;surf(x,y,z1);shading interp;


6.1
1imread imwrite imread imwrite
MATLAB
MATLAB
.bmp .jpg.jpeg.tif
2image imagesc
colormap
1-26 flower.jpg
[x,cmap]=imread('flower.jpg'); %
image(x);colormap(cmap);axis image off %
6.2
MATLAB getframemoviein movie
1getframe getframe (
) n

2moviein moviein(n) n
n

3movie movie(m,n) m n

1-27 peaks z
[X,Y,Z]=peaks(30); surf(X,Y,Z)axis([-3,3,-3,3,-10,10])axis off;shading
interp;colormap(hot);m=moviein(20); % 20 for
i=1:20view(-37.5+24*(i-1),30) % m(:,i)=getframe; %
m end movie(m,2); % 2

You might also like