1用plot函数绘制正弦曲线和余弦曲线x=0:0.1*pi:2*pi;y1=sin(x);y2=cos(x);plot(x,y1,'-.',x,y2,'s',x,y2);01234567-1-0.8-0.6-0.4-0.200.20.40.60.81x=-40:40;y=(1/2.498*10)*exp((-x.^2)/(2*10^2));plot(x,y);title('\alpha=0,\sigma=10的正态分布曲线');xlabel('x');ylabel('概率密度f(x)');-40-30-20-1001020304000.511.522.533.544.5=0,=10的正态分布曲线x概率密度f(x)2x=-pi:.01:pi;y1=sin(x);y2=cos(x);plot(x,y1,'r-',x,y2,'o');-4-3-2-101234-1-0.8-0.6-0.4-0.200.20.40.60.81绘制正弦曲线和余弦曲线x=-pi:.01:pi;y1=sin(x);y2=cos(x);plot(x,y1,'r-',x,y2,'o');legend('y=sin(x)','y=cos(x)');-4-3-2-101234-1-0.8-0.6-0.4-0.200.20.40.60.81y=sin(x)y=cos(x)3用text函数标出log函数的零点x=-2:.1:2;y=x.^2+2*x-3;plot(x,y);text(1,0,'\leftarrow零点');-2-1.5-1-0.500.511.52-4-3-2-1012345零点绘制正弦余弦和正切曲线x=0:.1:3*pi;y1=sin(x);y2=cos(x);y3=tan(x+eps);subplot(2,2,1:2);plot(x,y1);subplot(2,2,3);plot(x,y1);subplot(2,2,4);plot(x,y3);012345678910-1-0.500.510510-1-0.500.510510-500501004为坐标轴添加细网格t=0:.02:2*pi;plot(cos(t),sin(t));axisequal;gridminor;-1-0.500.51-0.8-0.6-0.4-0.200.20.40.60.8创建两个图形窗口并画图a=figurea=1x=1:10;y=x;plot(x,y);b=figureb=2plot(x,y.^2);figure(a);gridon;512345678910123456789101234567891001020304050607080901006在同一窗口绘制正弦和余弦曲线x=0:.02:2*pi;y1=sin(x);y2=cos(x);plot(x,y1);holdon;plot(x,y2);01234567-1-0.8-0.6-0.4-0.200.20.40.60.81hmp=@humps;subplot(2,1,1);fplot(hmp,[0,1]);sn=@(x)sin(1./x);subplot(2,1,2);fplot(sn,[.01,.1]);00.10.20.30.40.50.60.70.80.910204060801000.010.020.030.040.050.060.070.080.090.1-1-0.500.517绘制指数函数的爽对数坐标图x=logspace(-1,2);loglog(x,exp(x),'-s');gridon;10-110010110210010101020103010401050用两种方法绘制以10为底的对数函数x=0:.1:5;subplot(2,1,1);plot(x,log10(x));subplot(2,1,2);semilogx(x,log10(x));00.511.522.533.544.55-1-0.500.5110-1100101-1-0.500.518绘制极坐标图t=0:.01:2*pi;y=sin(5*t);polar(t,y);0.20.40.60.813021060240902701203001503301800t=0:.01:2*pi;y=sin(9*t);polar(t,y);0.20.40.60.8130210602409027012030015033018009a=round(rand(4,2)*10);subplot(2,2,1);bar(a,'grouped');title('grouped');subplot(2,2,2);bar(a,'stacked');title('stacked');subplot(2,2,3);barh(a,'stacked');title('stacked');subplot(2,2,4);bar(a,1.5');12340510grouped1234051015stacked0510151234stacked1234051010a=round(rand(4,2)*10);subplot(2,2,1);bar(a,'grouped');title('grouped');subplot(2,2,2);bar(a,'stacked');title('stacked');subplot(2,2,3);barh(a,'stacked');title('stacked');subplot(2,2,4);bar(a,1.5');title('width=1.5');12340510grouped1234051015stacked0510151234stacked12340510width=1.511绘制正弦函数的阶梯图x=-2*pi:.3:2*pi;stairs(x,sin(x));-8-6-4-202468-1-0.8-0.6-0.4-0.200.20.40.60.81隐函数绘制曲线colormap([0,0,1]);设置线条颜色subplot(2,2,1);ezplot('x^2+y^2/3-9');绘制椭圆subplot(2,2,2);ezplot('x^2+y/3-2');绘制抛物线subplot(2,2,3);ezplot('x^2-y/3-3');绘制双曲线subplot(2,2,4);ezplot('cos(t)','sin(t)^2');-505-505xyx2+y2/3-9=0-505-505xyx2+y/3-2=0-505-505xyx2-y/3-3=0-0.500.5100.51xyx=cos(t),y=sin(t)212填充一个六边形t=(0:1/6:1)*2*pi;x=cos(t);y=sin(t);fill(x,y,'m');-1-0.8-0.6-0.4-0.200.20.40.60.81-1-0.8-0.6-0.4-0.200.20.40.60.81在x轴上放大正弦曲线x=1:.2:10;y=sin(x);plot(x,y);zoomxon;12345678910-1-0.8-0.6-0.4-0.200.20.40.60.8113绘制复数的箭头图Z=eig(randn(10,10))Z=2.70372.1703+1.3780i2.1703-1.3780i1.6533-2.4172-0.6656+1.4599i-0.6656-1.4599i-1.2391+0.3929i-1.2391-0.3929i-0.3378compass(Z)123302106024090270120300150330180014绘制一个简单的彗星图t=0:.01:2*pi;x=cos(2*t).*(cos(t).^2);y=sin(2*t).*(sin(t).^2);comet(x,y);绘制误差棒图loadcount.dat载入matlab系统中自带的数据s=sum(count,2);计算总和stda=std(count,0,2);计算标准差errorbar(s,stda);画出每个位置的标准差0510152025010020030040050060015绘制角度均匀变化的向量theta=(-90:10:90)*pi/180;r=2*ones(size(theta));[u,v]=pol2cart(theta,r);feather(u,v);02468101214161820-2-1.5-1-0.500.511.52绘制正态分布数据的直方图x=-4:.1:4;y=randn(10000,1);hist(y,x);-5-4-3-2-101234505010015020025030035040045016绘制matlab自带数据的角度直方图figure;loadsunspot.dat载入数据rose(sunspot(:,2),12)分为12组绘制角度直方图102030403021060240902701203001503301800绘制向量0:99的傅里叶变换的离散数据图a=linspace(0,99);0到99,长度为100的等分向量b=fft(a);去傅里叶变换stem(abs(b))绘制傅里叶变换的离散数据图0102030405060708090100050010001500200025003000350040004500500017绘制简单的三维饼形图x=linspace(0,1,10);y=x/2;z=sin(x)+cos(y);stem3(x,y,z);00.20.40.60.8100.20.40.60.800.511.52