matlab基础作图实例

合集下载

第三章Matlab 绘图与例题 (1)

第三章Matlab 绘图与例题  (1)

[X ,Y ] meshgrid(x, y)
mesh(X ,Y , Z )
• mesh(Z) 若提供参数x,y,等价于mesh(x,y,Z),否 则默认
• mesxhc 1除: n了, y生1成: m网格曲面,还在xoy面上生成等高线图
• meshz 除了生成网格曲面,还在曲线下加上一个长方形 台柱。
机动 目录 上页 下页 返回 结束
空间网格曲面。而函数meshgrid就用来生成xoy 平面上的小矩形顶点坐标值的矩阵(格点矩阵)。 函数meshgrid也适用于三元函数。
meshgrid的调用形式
• [X,Y]=meshgrid(x,y) 绘制二维图形时生成小矩形的格点 • [X,Y]= meshgrid(x) 等价于[X,Y]=meshgrid(x,x) • [X,Y,Z]=meshgrid(x,y,z)绘制三维图形生成小矩形的格点 • [X,Y,Z]= meshgrid(x) 等价于[X,Y,Z]=meshgrid(x,x,x)
c青
x叉
> 右三角形 -- 划线
m 洋红 + 十字 < 左三角形
y黄
*星
p 五角形
k黑
s 方块 h 六角形
d 菱形
例、在同一图形窗口画出不同颜色,线形的正、余 弦图形
机动 目录 上页 下页 返回 结束
三、 基本绘图控制参数
常用作图指令 • 清除图形窗口 clf • 显示/不显示格栅 grid on/off • 保留/释放现有图形 hold on/off • 使用/不使用坐标框 box on/off • 暂停直到击键盘 pause
例3-1-1、在同一坐标系中画出两个函数 y cos 2x, y x 的图形,自变量范围为:2 x 2 ,及5个点

matlab编程实例100例

matlab编程实例100例

1-32是:图形应用篇33-66是:界面设计篇67-84是:图形处理篇85-100是:数值分析篇实例1:三角函数曲线(1)function shili01h0=figure('toolbar','none',...'position',[198 56 350 300],...'name','实例01');h1=axes('parent',h0,...'visible','off');x=-pi:0.05:pi;y=sin(x);plot(x,y);xlabel('自变量X');ylabel('函数值Y');title('SIN( )函数曲线');grid on实例2:三角函数曲线(2)function shili02h0=figure('toolbar','none',...'position',[200 150 450 350],...'name','实例02');x=-pi:0.05:pi;y=sin(x)+cos(x);plot(x,y,'-*r','linewidth',1);grid onxlabel('自变量X');ylabel('函数值Y');title('三角函数');实例3:图形的叠加function shili03h0=figure('toolbar','none',...'position',[200 150 450 350],...'name','实例03');x=-pi:0.05:pi;y1=sin(x);y2=cos(x);plot(x,y1,...'-*r',...x,y2,...'--og');grid onxlabel('自变量X');ylabel('函数值Y');title('三角函数');实例4:双y轴图形的绘制function shili04h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例04');x=0:900;a=1000;b=0.005;y1=2*x;y2=cos(b*x);[haxes,hline1,hline2]=plotyy(x,y1,x,y2,'semilogy','plot'); axes(haxes(1))ylabel('semilog plot');axes(haxes(2))ylabel('linear plot');实例5:单个轴窗口显示多个图形function shili05h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例05');t=0:pi/10:2*pi;[x,y]=meshgrid(t);subplot(2,2,1)plot(sin(t),cos(t))axis equalsubplot(2,2,2)z=sin(x)-cos(y);plot(t,z)axis([0 2*pi -2 2])subplot(2,2,3)h=sin(x)+cos(y);plot(t,h)axis([0 2*pi -2 2])subplot(2,2,4)g=(sin(x).^2)-(cos(y).^2);plot(t,g)axis([0 2*pi -1 1])实例6:图形标注function shili06h0=figure('toolbar','none',...'position',[200 150 450 400],...'name','实例06');t=0:pi/10:2*pi;h=plot(t,sin(t));xlabel('t=0到2\pi','fontsize',16);ylabel('sin(t)','fontsize',16);title('\it{从0to2\pi 的正弦曲线}','fontsize',16) x=get(h,'xdata');y=get(h,'ydata');imin=find(min(y)==y);imax=find(max(y)==y);text(x(imin),y(imin),...['\leftarrow最小值=',num2str(y(imin))],...'fontsize',16)text(x(imax),y(imax),...['\leftarrow最大值=',num2str(y(imax))],...'fontsize',16)实例7:条形图形function shili07h0=figure('toolbar','none',...'position',[200 150 450 350],...'name','实例07');tiao1=[562 548 224 545 41 445 745 512];tiao2=[47 48 57 58 54 52 65 48];t=0:7;bar(t,tiao1)xlabel('X轴');ylabel('TIAO1值');h1=gca;h2=axes('position',get(h1,'position'));plot(t,tiao2,'linewidth',3)set(h2,'yaxislocation','right','color','none','xticklabel',[]) 实例8:区域图形function shili08h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例08');x=91:95;profits1=[88 75 84 93 77];profits2=[51 64 54 56 68];profits3=[42 54 34 25 24];profits4=[26 38 18 15 4];area(x,profits1,'facecolor',[0.5 0.9 0.6],...'edgecolor','b',...'linewidth',3)hold onarea(x,profits2,'facecolor',[0.9 0.85 0.7],...'edgecolor','y',...'linewidth',3)hold onarea(x,profits3,'facecolor',[0.3 0.6 0.7],...'edgecolor','r',...'linewidth',3)hold onarea(x,profits4,'facecolor',[0.6 0.5 0.9],...'edgecolor','m',...'linewidth',3)hold offset(gca,'xtick',[91:95])set(gca,'layer','top')gtext('\leftarrow第一季度销量')gtext('\leftarrow第二季度销量')gtext('\leftarrow第三季度销量')gtext('\leftarrow第四季度销量')xlabel('年','fontsize',16);ylabel('销售量','fontsize',16);实例9:饼图的绘制function shili09h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例09');t=[54 21 35;68 54 35;45 25 12;48 68 45;68 54 69];x=sum(t);h=pie(x);textobjs=findobj(h,'type','text');str1=get(textobjs,{'string'});val1=get(textobjs,{'extent'});oldext=cat(1,val1{:});names={'商品一:';'商品二:';'商品三:'};str2=strcat(names,str1);set(textobjs,{'string'},str2)val2=get(textobjs,{'extent'});newext=cat(1,val2{:});offset=sign(oldext(:,1)).*(newext(:,3)-oldext(:,3))/2; pos=get(textobjs,{'position'});textpos=cat(1,pos{:});textpos(:,1)=textpos(:,1)+offset;set(textobjs,{'position'},num2cell(textpos,[3,2]))实例10:阶梯图function shili10h0=figure('toolbar','none',...'position',[200 150 450 400],...'name','实例10');a=0.01;b=0.5;t=0:10;f=exp(-a*t).*sin(b*t);stairs(t,f)hold onplot(t,f,':*')hold offglabel='函数e^{-(\alpha*t)}sin\beta*t的阶梯图'; gtext(glabel,'fontsize',16)xlabel('t=0:10','fontsize',16)axis([0 10 -1.2 1.2])实例11:枝干图function shili11h0=figure('toolbar','none',...'position',[200 150 450 350],...'name','实例11');x=0:pi/20:2*pi;y1=sin(x);y2=cos(x);h1=stem(x,y1+y2);hold onh2=plot(x,y1,'^r',x,y2,'*g');hold offh3=[h1(1);h2];legend(h3,'y1+y2','y1=sin(x)','y2=cos(x)') xlabel('自变量X');ylabel('函数值Y');title('正弦函数与余弦函数的线性组合');实例12:罗盘图function shili12h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例12');winddirection=[54 24 65 84256 12 235 62125 324 34 254];windpower=[2 5 5 36 8 12 76 14 10 8];rdirection=winddirection*pi/180;[x,y]=pol2cart(rdirection,windpower); compass(x,y);desc={'风向和风力','气象台','10月1日0:00到','10月1日12:00'};gtext(desc)实例13:轮廓图function shili13h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例13');[th,r]=meshgrid((0:10:360)*pi/180,0:0.05:1); [x,y]=pol2cart(th,r);z=x+i*y;f=(z.^4-1).^(0.25);contour(x,y,abs(f),20)axis equalxlabel('实部','fontsize',16);ylabel('虚部','fontsize',16);h=polar([0 2*pi],[0 1]);delete(h)hold oncontour(x,y,abs(f),20)实例14:交互式图形function shili14h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例14');axis([0 10 0 10]);hold onx=[];y=[];n=0;disp('单击鼠标左键点取需要的点'); disp('单击鼠标右键点取最后一个点'); but=1;while but==1[xi,yi,but]=ginput(1);plot(xi,yi,'bo')n=n+1;disp('单击鼠标左键点取下一个点');x(n,1)=xi;y(n,1)=yi;endt=1:n;ts=1:0.1:n;xs=spline(t,x,ts);ys=spline(t,y,ts);plot(xs,ys,'r-');hold off实例14:交互式图形function shili14h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例14');axis([0 10 0 10]);hold onx=[];y=[];n=0;disp('单击鼠标左键点取需要的点'); disp('单击鼠标右键点取最后一个点'); but=1;while but==1[xi,yi,but]=ginput(1);plot(xi,yi,'bo')n=n+1;disp('单击鼠标左键点取下一个点');x(n,1)=xi;y(n,1)=yi;endt=1:n;ts=1:0.1:n;xs=spline(t,x,ts);ys=spline(t,y,ts);plot(xs,ys,'r-');hold off实例15:变换的傅立叶函数曲线function shili15h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例15');axis equalm=moviein(20,gcf);set(gca,'nextplot','replacechildren') h=uicontrol('style','slider','position',...[100 10 500 20],'min',1,'max',20) for j=1:20plot(fft(eye(j+16)))set(h,'value',j)m(:,j)=getframe(gcf);endclf;axes('position',[0 0 1 1]);movie(m,30)实例16:劳伦兹非线形方程的无序活动function shili15h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例15');axis equalm=moviein(20,gcf);set(gca,'nextplot','replacechildren') h=uicontrol('style','slider','position',...[100 10 500 20],'min',1,'max',20) for j=1:20plot(fft(eye(j+16)))set(h,'value',j)m(:,j)=getframe(gcf);endclf;axes('position',[0 0 1 1]);movie(m,30)实例17:填充图function shili17h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例17');t=(1:2:15)*pi/8;x=sin(t);y=cos(t);fill(x,y,'r')axis square offtext(0,0,'STOP',...'color',[1 1 1],...'fontsize',50,...'horizontalalignment','center') 例18:条形图和阶梯形图function shili18h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例18');subplot(2,2,1)x=-3:0.2:3;y=exp(-x.*x);bar(x,y)title('2-D Bar Chart')subplot(2,2,2)x=-3:0.2:3;y=exp(-x.*x);bar3(x,y,'r')title('3-D Bar Chart')subplot(2,2,3)x=-3:0.2:3;y=exp(-x.*x);stairs(x,y)title('Stair Chart')subplot(2,2,4)x=-3:0.2:3;y=exp(-x.*x);barh(x,y)title('Horizontal Bar Chart')实例19:三维曲线图function shili19h0=figure('toolbar','none',...'position',[200 150 450 400],...'name','实例19');subplot(2,1,1)x=linspace(0,2*pi);y1=sin(x);y2=cos(x);y3=sin(x)+cos(x);z1=zeros(size(x));z2=0.5*z1;z3=z1;plot3(x,y1,z1,x,y2,z2,x,y3,z3)grid onxlabel('X轴');ylabel('Y轴');zlabel('Z轴');title('Figure1:3-D Plot')subplot(2,1,2)x=linspace(0,2*pi);y1=sin(x);y2=cos(x);y3=sin(x)+cos(x);z1=zeros(size(x));z2=0.5*z1;z3=z1;plot3(x,z1,y1,x,z2,y2,x,z3,y3)grid onxlabel('X轴');ylabel('Y轴');zlabel('Z轴');title('Figure2:3-D Plot')实例20:图形的隐藏属性function shili20h0=figure('toolbar','none',...'position',[200 150 450 300],...'name','实例20');subplot(1,2,1)[x,y,z]=sphere(10);mesh(x,y,z)axis offtitle('Figure1:Opaque')hidden onsubplot(1,2,2)[x,y,z]=sphere(10);mesh(x,y,z)axis offtitle('Figure2:Transparent') hidden off实例21PEAKS函数曲线function shili21h0=figure('toolbar','none',...'position',[200 100 450 450],...'name','实例21');[x,y,z]=peaks(30);subplot(2,1,1)x=x(1,:);y=y(:,1);i=find(y>0.8&y<1.2);j=find(x>-0.6&x<0.5);z(i,j)=nan*z(i,j);surfc(x,y,z)xlabel('X轴');ylabel('Y轴');zlabel('Z轴');title('Figure1:surfc函数形成的曲面') subplot(2,1,2)x=x(1,:);y=y(:,1);i=find(y>0.8&y<1.2);j=find(x>-0.6&x<0.5);z(i,j)=nan*z(i,j);surfl(x,y,z)xlabel('X轴');ylabel('Y轴');zlabel('Z轴');title('Figure2:surfl函数形成的曲面')实例22:片状图function shili22h0=figure('toolbar','none',...'position',[200 150 550 350],...'name','实例22');subplot(1,2,1)x=rand(1,20);y=rand(1,20);z=peaks(x,y*pi);t=delaunay(x,y);trimesh(t,x,y,z)hidden offtitle('Figure1:Triangular Surface Plot'); subplot(1,2,2)x=rand(1,20);y=rand(1,20);z=peaks(x,y*pi);t=delaunay(x,y);trisurf(t,x,y,z)title('Figure1:Triangular Surface Plot'); 实例23:视角的调整function shili23h0=figure('toolbar','none',...'position',[200 150 450 350],...'name','实例23');x=-5:0.5:5;[x,y]=meshgrid(x);r=sqrt(x.^2+y.^2)+eps;z=sin(r)./r;subplot(2,2,1)surf(x,y,z)xlabel('X-axis')ylabel('Y-axis')zlabel('Z-axis')title('Figure1')view(-37.5,30)subplot(2,2,2)surf(x,y,z)xlabel('X-axis')ylabel('Y-axis')zlabel('Z-axis')title('Figure2')view(-37.5+90,30)subplot(2,2,3)surf(x,y,z)xlabel('X-axis')ylabel('Y-axis')zlabel('Z-axis')title('Figure3')view(-37.5,60)subplot(2,2,4)surf(x,y,z)xlabel('X-axis')ylabel('Y-axis')zlabel('Z-axis')title('Figure4')view(180,0)实例24:向量场的绘制function shili24h0=figure('toolbar','none',...'position',[200 150 450 350],...'name','实例24');subplot(2,2,1)z=peaks;ribbon(z)title('Figure1')subplot(2,2,2)[x,y,z]=peaks(15);[dx,dy]=gradient(z,0.5,0.5); contour(x,y,z,10)hold onquiver(x,y,dx,dy)hold offtitle('Figure2')subplot(2,2,3)[x,y,z]=peaks(15);[nx,ny,nz]=surfnorm(x,y,z);surf(x,y,z)hold onquiver3(x,y,z,nx,ny,nz)hold offtitle('Figure3')subplot(2,2,4)x=rand(3,5);y=rand(3,5);z=rand(3,5);c=rand(3,5);fill3(x,y,z,c)grid ontitle('Figure4')实例25:灯光定位function shili25h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例25');vert=[1 1 1;1 2 1;2 2 1;2 1 1;1 1 2;12 2;2 2 2;2 1 2];fac=[1 2 3 4;2 6 7 3;4 3 7 8;15 8 4;1 2 6 5;5 6 7 8];grid offsphere(36)h=findobj('type','surface');set(h,'facelighting','phong',...'facecolor',...'interp',...'edgecolor',[0.4 0.4 0.4],...'backfacelighting',...'lit')hold onpatch('faces',fac,'vertices',vert,...'facecolor','y');light('position',[1 3 2]);light('position',[-3 -1 3]); material shinyaxis vis3d offhold off实例26:柱状图function shili26h0=figure('toolbar','none',...'position',[200 50 450 450],...'name','实例26');subplot(2,1,1)x=[5 2 18 7 39 8 65 5 54 3 2];bar(x)xlabel('X轴');ylabel('Y轴');title('第一子图');subplot(2,1,2)y=[5 2 18 7 39 8 65 5 54 3 2];barh(y)xlabel('X轴');ylabel('Y轴');title('第二子图');实例27:设置照明方式function shili27h0=figure('toolbar','none',...'position',[200 150 450 350],...'name','实例27');subplot(2,2,1)sphereshading flatcamlight leftcamlight rightlighting flatcolorbaraxis offtitle('Figure1')subplot(2,2,2)sphereshading flatcamlight leftcamlight rightlighting gouraudcolorbaraxis offtitle('Figure2')subplot(2,2,3)sphereshading interpcamlight rightcamlight leftlighting phongcolorbaraxis offtitle('Figure3')subplot(2,2,4)sphereshading flatcamlight leftcamlight rightlighting nonecolorbaraxis offtitle('Figure4')实例28:羽状图function shili28h0=figure('toolbar','none',...'position',[200 150 450 350],...'name','实例28');subplot(2,1,1)alpha=90:-10:0;r=ones(size(alpha));m=alpha*pi/180;n=r*10;[u,v]=pol2cart(m,n);feather(u,v)title('羽状图')axis([0 20 0 10])subplot(2,1,2)t=0:0.5:10;x=0.05+i;y=exp(-x*t);feather(y)title('复数矩阵的羽状图')实例29:立体透视(1)function shili29h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例29');[x,y,z]=meshgrid(-2:0.1:2,...-2:0.1:2,...-2:0.1:2);v=x.*exp(-x.^2-y.^2-z.^2);grid onfor i=-2:0.5:2;h1=surf(linspace(-2,2,20),...linspace(-2,2,20),...zeros(20)+i);rotate(h1,[1 -1 1],30)dx=get(h1,'xdata');dy=get(h1,'ydata');dz=get(h1,'zdata');delete(h1)slice(x,y,z,v,[-2 2],2,-2)hold onslice(x,y,z,v,dx,dy,dz)hold offaxis tightview(-5,10)drawnowend实例30:立体透视(2)function shili30h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例30');[x,y,z]=meshgrid(-2:0.1:2,...-2:0.1:2,...-2:0.1:2);v=x.*exp(-x.^2-y.^2-z.^2); [dx,dy,dz]=cylinder;slice(x,y,z,v,[-2 2],2,-2)for i=-2:0.2:2h=surface(dx+i,dy,dz);rotate(h,[1 0 0],90)xp=get(h,'xdata');yp=get(h,'ydata');zp=get(h,'zdata');delete(h)hold onhs=slice(x,y,z,v,xp,yp,zp);axis tightxlim([-3 3])view(-10,35)drawnowdelete(hs)hold offend实例31:表面图形function shili31h0=figure('toolbar','none',...'position',[200 150 550 250],...'name','实例31');subplot(1,2,1)x=rand(100,1)*16-8;y=rand(100,1)*16-8;r=sqrt(x.^2+y.^2)+eps;z=sin(r)./r;xlin=linspace(min(x),max(x),33); ylin=linspace(min(y),max(y),33); [X,Y]=meshgrid(xlin,ylin);Z=griddata(x,y,z,X,Y,'cubic'); mesh(X,Y,Z)axis tighthold onplot3(x,y,z,'.','Markersize',20)subplot(1,2,2)k=5;n=2^k-1;theta=pi*(-n:2:n)/n;phi=(pi/2)*(-n:2:n)'/n;X=cos(phi)*cos(theta);Y=cos(phi)*sin(theta);Z=sin(phi)*ones(size(theta));colormap([0 0 0;1 1 1])C=hadamard(2^k);surf(X,Y,Z,C)axis square实例32:沿曲线移动的小球h0=figure('toolbar','none',...'position',[198 56 408 468],...'name','实例32');h1=axes('parent',h0,...'position',[0.15 0.45 0.7 0.5],...'visible','on');t=0:pi/24:4*pi;y=sin(t);plot(t,y,'b')n=length(t);h=line('color',[0 0.5 0.5],...'linestyle','.',...'markersize',25,...'erasemode','xor');k1=uicontrol('parent',h0,...'style','pushbutton',...'position',[80 100 50 30],...'string','开始',...'callback',[...'i=1;',...'k=1;,',...'m=0;,',...'while 1,',...'if k==0,',...'break,',...'end,',...'if k~=0,',...'set(h,''xdata'',t(i),''ydata'',y(i)),',...'drawnow;,',...'i=i+1;,',...'if i>n,',...'m=m+1;,',...'i=1;,',...'end,',...'end,',...'end']);k2=uicontrol('parent',h0,...'style','pushbutton',...'position',[180 100 50 30],...'string','停止',...'callback',[...'k=0;,',...'set(e1,''string'',m),',...'p=get(h,''xdata'');,',...'q=get(h,''ydata'');,',...'set(e2,''string'',p);,',...'set(e3,''string'',q)']); k3=uicontrol('parent',h0,...'style','pushbutton',...'position',[280 100 50 30],...'string','关闭',...'callback','close');e1=uicontrol('parent',h0,...'style','edit',...'position',[60 30 60 20]);t1=uicontrol('parent',h0,...'style','text',...'string','循环次数',...'position',[60 50 60 20]);e2=uicontrol('parent',h0,...'style','edit',...'position',[180 30 50 20]); t2=uicontrol('parent',h0,...'style','text',...'string','终点的X坐标值',...'position',[155 50 100 20]); e3=uicontrol('parent',h0,...'style','edit',...'position',[300 30 50 20]); t3=uicontrol('parent',h0,...'style','text',...'string','终点的Y坐标值',...'position',[275 50 100 20]);实例33:曲线转换按钮h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例33');x=0:0.5:2*pi;y=sin(x);h=plot(x,y);grid onhuidiao=[...'if i==1,',...'i=0;,',...'y=cos(x);,',...'delete(h),',...'set(hm,''string'',''正弦函数''),',...'h=plot(x,y);,',...'grid on,',...'else if i==0,',...'i=1;,',...'y=sin(x);,',...'set(hm,''string'',''余弦函数''),',...'delete(h),',...'h=plot(x,y);,',...'grid on,',...'end,',...'end'];hm=uicontrol(gcf,'style','pushbutton',...'string','余弦函数',...'callback',huidiao);i=1;set(hm,'position',[250 20 60 20]);set(gca,'position',[0.2 0.2 0.6 0.6])title('按钮的使用')hold on实例34:栅格控制按钮h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例34');x=0:0.5:2*pi;y=sin(x);plot(x,y)huidiao1=[...'set(h_toggle2,''value'',0),',...'grid on,',...];huidiao2=[...'set(h_toggle1,''value'',0),',...'grid off,',...];h_toggle1=uicontrol(gcf,'style','togglebutton',...'string','grid on',...'value',0,...'position',[20 45 50 20],...'callback',huidiao1);h_toggle2=uicontrol(gcf,'style','togglebutton',...'string','grid off',...'value',0,...'position',[20 20 50 20],...'callback',huidiao2);set(gca,'position',[0.2 0.2 0.6 0.6])title('开关按钮的使用')实例35:编辑框的使用h0=figure('toolbar','none',...'position',[200 150 350 250],...'name','实例35');f='Please input the letter';huidiao1=[...'g=upper(f);,',...'set(h2_edit,''string'',g),',...];huidiao2=[...'g=lower(f);,',...'set(h2_edit,''string'',g),',...];h1_edit=uicontrol(gcf,'style','edit',...'position',[100 200 100 50],...'HorizontalAlignment','left',...'string','Please input the letter',...'callback','f=get(h1_edit,''string'');',...'background','w',...'max',5,...'min',1);h2_edit=uicontrol(gcf,'style','edit',...'HorizontalAlignment','left',...'position',[100 100 100 50],...'max',5,...'min',1);h1_button=uicontrol(gcf,'style','pushbutton',...'string','小写变大写',...'position',[100 45 100 20],...'callback',huidiao1);h2_button=uicontrol(gcf,'style','pushbutton',...'string','大写变小写',...'position',[100 20 100 20],...'callback',huidiao2);实例36:弹出式菜单h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例36');x=0:0.5:2*pi;y=sin(x);h=plot(x,y);grid onhm=uicontrol(gcf,'style','popupmenu',...'string',...'sin(x)|cos(x)|sin(x)+cos(x)|exp(-sin(x))',...'position',[250 20 50 20]);set(hm,'value',1)huidiao=[...'v=get(hm,''value'');,',...'switch v,',...'case 1,',...'delete(h),',...'y=sin(x);,',...'h=plot(x,y);,',...'grid on,',...'case 2,',...'delete(h),',...'y=cos(x);,',...'h=plot(x,y);,',...'grid on,',...'case 3,',...'delete(h),',...'y=sin(x)+cos(x);,',...'h=plot(x,y);,',...'grid on,',...'case 4,',...'y=exp(-sin(x));,',...'h=plot(x,y);,',...'grid on,',...'end'];set(hm,'callback',huidiao)set(gca,'position',[0.2 0.2 0.6 0.6])title('弹出式菜单的使用')实例37:滑标的使用h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例37');[x,y]=meshgrid(-8:0.5:8);r=sqrt(x.^2+y.^2)+eps;z=sin(r)./r;h0=mesh(x,y,z);h1=axes('position',...[0.2 0.2 0.5 0.5],...'visible','off');htext=uicontrol(gcf,...'units','points',...'position',[20 30 45 15],...'string','brightness',...'style','text');hslider=uicontrol(gcf,...'units','points',...'position',[10 10 300 15],...'min',-1,...'max',1,...'style','slider',...'callback',...'brighten(get(hslider,''value''))');实例38:多选菜单h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例38');[x,y]=meshgrid(-8:0.5:8);r=sqrt(x.^2+y.^2)+eps;z=sin(r)./r;h0=mesh(x,y,z);hlist=uicontrol(gcf,'style','listbox',...'string','default|spring|summer|autumn|winter',...'max',5,...'min',1,...'position',[20 20 80 100],...'callback',[...'k=get(hlist,''value'');,',...'switch k,',...'case 1,',...'colormap default,',...'case 2,',...'colormap spring,',...'case 3,',...'colormap summer,',...'case 4,',...'colormap autumn,',...'case 5,',...'colormap winter,',...'end']);实例39:菜单控制的使用h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例39');x=0:0.5:2*pi;y=cos(x);h=plot(x,y);grid onset(gcf,'toolbar','none')hm=uimenu('label','example');huidiao1=[...'set(hm_gridon,''checked'',''on''),',...'set(hm_gridoff,''checked'',''off''),',...'grid on'];huidiao2=[...'set(hm_gridoff,''checked'',''on''),',...'set(hm_gridon,''checked'',''off''),',...'grid off'];hm_gridon=uimenu(hm,'label','grid on',...'checked','on',...'callback',huidiao1);hm_gridoff=uimenu(hm,'label','grid off',...'checked','off',...'callback',huidiao2);实例40:UIMENU菜单的应用。

matlab编程实例100例(精编文档).doc

matlab编程实例100例(精编文档).doc

【最新整理,下载后即可编辑】1-32是:图形应用篇33-66是:界面设计篇67-84是:图形处理篇85-100是:数值分析篇实例1:三角函数曲线(1)function shili01h0=figure('toolbar','none',...'position',[198****0300],...'name','实例01');h1=axes('parent',h0,...'visible','off');x=-pi:0.05:pi;y=sin(x);plot(x,y);xlabel('自变量X');ylabel('函数值Y');title('SIN( )函数曲线');grid on实例2:三角函数曲线(2)function shili02h0=figure('toolbar','none',...'position',[200 150 450 350],...'name','实例02');x=-pi:0.05:pi;y=sin(x)+cos(x);plot(x,y,'-*r','linewidth',1);grid onxlabel('自变量X');ylabel('函数值Y');title('三角函数');实例3:图形的叠加function shili03h0=figure('toolbar','none',...'position',[200 150 450 350],...'name','实例03');x=-pi:0.05:pi;y1=sin(x);y2=cos(x);plot(x,y1,...'-*r',...x,y2,...'--og');grid onxlabel('自变量X');ylabel('函数值Y');title('三角函数');实例4:双y轴图形的绘制function shili04h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例04');x=0:900;a=1000;b=0.005;y1=2*x;y2=cos(b*x);[haxes,hline1,hline2]=plotyy(x,y1,x,y2,'semilogy','plot'); axes(haxes(1))ylabel('semilog plot');axes(haxes(2))ylabel('linear plot');实例5:单个轴窗口显示多个图形function shili05h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例05');t=0:pi/10:2*pi;[x,y]=meshgrid(t);subplot(2,2,1)plot(sin(t),cos(t))axis equalsubplot(2,2,2)z=sin(x)-cos(y);plot(t,z)axis([0 2*pi -2 2])subplot(2,2,3)h=sin(x)+cos(y);plot(t,h)axis([0 2*pi -2 2])subplot(2,2,4)g=(sin(x).^2)-(cos(y).^2);plot(t,g)axis([0 2*pi -1 1])实例6:图形标注function shili06h0=figure('toolbar','none',...'position',[200 150 450 400],...'name','实例06');t=0:pi/10:2*pi;h=plot(t,sin(t));xlabel('t=0到2\pi','fontsize',16);ylabel('sin(t)','fontsize',16);title('\it{从0to2\pi 的正弦曲线}','fontsize',16) x=get(h,'xdata');y=get(h,'ydata');imin=find(min(y)==y);imax=find(max(y)==y);text(x(imin),y(imin),...['\leftarrow最小值=',num2str(y(imin))],...'fontsize',16)text(x(imax),y(imax),...['\leftarrow最大值=',num2str(y(imax))],...'fontsize',16)实例7:条形图形function shili07h0=figure('toolbar','none',...'position',[200 150 450 350],...'name','实例07');tiao1=[562 548 224 545 41 445 745 512];tiao2=[47 48 57 58 54 52 65 48];t=0:7;bar(t,tiao1)xlabel('X轴');ylabel('TIAO1值');h1=gca;h2=axes('position',get(h1,'position'));plot(t,tiao2,'linewidth',3)set(h2,'yaxislocation','right','color','none','xticklabel',[]) 实例8:区域图形function shili08h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例08');x=91:95;profits1=[88 75 84 93 77];profits2=[51 64 54 56 68];profits3=[42 54 34 25 24];profits4=[26 38 18 15 4];area(x,profits1,'facecolor',[0.5 0.9 0.6],...'edgecolor','b',...'linewidth',3)hold onarea(x,profits2,'facecolor',[0.9 0.85 0.7],...'edgecolor','y',...'linewidth',3)hold onarea(x,profits3,'facecolor',[0.3 0.6 0.7],...'edgecolor','r',...'linewidth',3)hold onarea(x,profits4,'facecolor',[0.6 0.5 0.9],...'edgecolor','m',...'linewidth',3)hold offset(gca,'xtick',[91:95])set(gca,'layer','top')gtext('\leftarrow第一季度销量') gtext('\leftarrow第二季度销量') gtext('\leftarrow第三季度销量') gtext('\leftarrow第四季度销量') xlabel('年','fontsize',16);ylabel('销售量','fontsize',16);实例9:饼图的绘制function shili09h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例09');t=[54 21 35;68 54 35;45 25 12;48 68 45;68 54 69];x=sum(t);h=pie(x);textobjs=findobj(h,'type','text');str1=get(textobjs,{'string'});val1=get(textobjs,{'extent'});oldext=cat(1,val1{:});names={'商品一:';'商品二:';'商品三:'};str2=strcat(names,str1);set(textobjs,{'string'},str2)val2=get(textobjs,{'extent'});newext=cat(1,val2{:});offset=sign(oldext(:,1)).*(newext(:,3)-oldext(:,3))/2; pos=get(textobjs,{'position'});textpos=cat(1,pos{:});textpos(:,1)=textpos(:,1)+offset;set(textobjs,{'position'},num2cell(textpos,[3,2]))实例10:阶梯图function shili10h0=figure('toolbar','none',...'position',[200 150 450 400],...'name','实例10');a=0.01;b=0.5;t=0:10;f=exp(-a*t).*sin(b*t);stairs(t,f)hold onplot(t,f,':*')hold offglabel='函数e^{-(\alpha*t)}sin\beta*t的阶梯图'; gtext(glabel,'fontsize',16)xlabel('t=0:10','fontsize',16)axis([0 10 -1.2 1.2])实例11:枝干图function shili11h0=figure('toolbar','none',...'position',[200 150 450 350],...'name','实例11');x=0:pi/20:2*pi;y1=sin(x);y2=cos(x);h1=stem(x,y1+y2);hold onh2=plot(x,y1,'^r',x,y2,'*g');hold offh3=[h1(1);h2];legend(h3,'y1+y2','y1=sin(x)','y2=cos(x)') xlabel('自变量X');ylabel('函数值Y');title('正弦函数与余弦函数的线性组合'); 实例12:罗盘图function shili12h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例12');winddirection=[54 24 65 84256 12 235 62125 324 34 254];windpower=[2 5 5 36 8 12 76 14 10 8];rdirection=winddirection*pi/180;[x,y]=pol2cart(rdirection,windpower); compass(x,y);desc={'风向和风力','北京气象台','10月1日0:00到','10月1日12:00'};gtext(desc)实例13:轮廓图function shili13h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例13');[th,r]=meshgrid((0:10:360)*pi/180,0:0.05:1); [x,y]=pol2cart(th,r);z=x+i*y;f=(z.^4-1).^(0.25);contour(x,y,abs(f),20)axis equalxlabel('实部','fontsize',16);ylabel('虚部','fontsize',16);h=polar([0 2*pi],[0 1]);delete(h)hold oncontour(x,y,abs(f),20)实例14:交互式图形function shili14h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例14');axis([0 10 0 10]);hold onx=[];y=[];n=0;disp('单击鼠标左键点取需要的点'); disp('单击鼠标右键点取最后一个点'); but=1;while but==1[xi,yi,but]=ginput(1);plot(xi,yi,'bo')n=n+1;disp('单击鼠标左键点取下一个点');x(n,1)=xi;y(n,1)=yi;endt=1:n;ts=1:0.1:n;xs=spline(t,x,ts);ys=spline(t,y,ts);plot(xs,ys,'r-');hold off实例14:交互式图形function shili14h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例14');axis([0 10 0 10]);hold onx=[];y=[];n=0;disp('单击鼠标左键点取需要的点'); disp('单击鼠标右键点取最后一个点'); but=1;while but==1[xi,yi,but]=ginput(1);plot(xi,yi,'bo')n=n+1;disp('单击鼠标左键点取下一个点');x(n,1)=xi;y(n,1)=yi;endt=1:n;ts=1:0.1:n;xs=spline(t,x,ts);ys=spline(t,y,ts);plot(xs,ys,'r-');hold off实例15:变换的傅立叶函数曲线function shili15h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例15');axis equalm=moviein(20,gcf);set(gca,'nextplot','replacechildren')h=uicontrol('style','slider','position',...[100 10 500 20],'min',1,'max',20)for j=1:20plot(fft(eye(j+16)))set(h,'value',j)m(:,j)=getframe(gcf);endclf;axes('position',[0 0 1 1]);movie(m,30)实例16:劳伦兹非线形方程的无序活动function shili15h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例15');axis equalm=moviein(20,gcf);set(gca,'nextplot','replacechildren')h=uicontrol('style','slider','position',...[100 10 500 20],'min',1,'max',20)for j=1:20plot(fft(eye(j+16)))set(h,'value',j)m(:,j)=getframe(gcf);endclf;axes('position',[0 0 1 1]);movie(m,30)实例17:填充图function shili17h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例17');t=(1:2:15)*pi/8;x=sin(t);y=cos(t);fill(x,y,'r')axis square offtext(0,0,'STOP',...'color',[1 1 1],...'fontsize',50,...'horizontalalignment','center') 例18:条形图和阶梯形图function shili18h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例18');subplot(2,2,1)x=-3:0.2:3;y=exp(-x.*x);bar(x,y)title('2-D Bar Chart')subplot(2,2,2)x=-3:0.2:3;y=exp(-x.*x);bar3(x,y,'r')title('3-D Bar Chart')subplot(2,2,3)x=-3:0.2:3;y=exp(-x.*x);stairs(x,y)title('Stair Chart')subplot(2,2,4)x=-3:0.2:3;y=exp(-x.*x);barh(x,y)title('Horizontal Bar Chart')实例19:三维曲线图function shili19h0=figure('toolbar','none',...'position',[200 150 450 400],...'name','实例19');subplot(2,1,1)x=linspace(0,2*pi);y1=sin(x);y2=cos(x);y3=sin(x)+cos(x);z1=zeros(size(x));z2=0.5*z1;z3=z1;plot3(x,y1,z1,x,y2,z2,x,y3,z3)grid onxlabel('X轴');ylabel('Y轴');zlabel('Z轴');title('Figure1:3-D Plot')subplot(2,1,2)x=linspace(0,2*pi);y1=sin(x);y2=cos(x);y3=sin(x)+cos(x);z1=zeros(size(x));z2=0.5*z1;z3=z1;plot3(x,z1,y1,x,z2,y2,x,z3,y3)grid onxlabel('X轴');ylabel('Y轴');zlabel('Z轴');title('Figure2:3-D Plot')实例20:图形的隐藏属性function shili20h0=figure('toolbar','none',...'position',[200 150 450 300],...'name','实例20');subplot(1,2,1)[x,y,z]=sphere(10);mesh(x,y,z)axis offtitle('Figure1:Opaque')hidden onsubplot(1,2,2)[x,y,z]=sphere(10);mesh(x,y,z)axis offtitle('Figure2:Transparent') hidden off实例21PEAKS函数曲线function shili21h0=figure('toolbar','none',...'position',[200 100 450 450],...'name','实例21');[x,y,z]=peaks(30);subplot(2,1,1)x=x(1,:);y=y(:,1);i=find(y>0.8&y<1.2);j=find(x>-0.6&x<0.5);z(i,j)=nan*z(i,j);surfc(x,y,z)xlabel('X轴');ylabel('Y轴');zlabel('Z轴');title('Figure1:surfc函数形成的曲面') subplot(2,1,2)x=x(1,:);y=y(:,1);i=find(y>0.8&y<1.2);j=find(x>-0.6&x<0.5);z(i,j)=nan*z(i,j);surfl(x,y,z)xlabel('X轴');ylabel('Y轴');zlabel('Z轴');title('Figure2:surfl函数形成的曲面') 实例22:片状图function shili22h0=figure('toolbar','none',...'position',[200 150 550 350],...'name','实例22');subplot(1,2,1)x=rand(1,20);y=rand(1,20);z=peaks(x,y*pi);t=delaunay(x,y);trimesh(t,x,y,z)hidden offtitle('Figure1:Triangular Surface Plot'); subplot(1,2,2)x=rand(1,20);y=rand(1,20);z=peaks(x,y*pi);t=delaunay(x,y);trisurf(t,x,y,z)title('Figure1:Triangular Surface Plot'); 实例23:视角的调整function shili23h0=figure('toolbar','none',...'position',[200 150 450 350],...'name','实例23');x=-5:0.5:5;[x,y]=meshgrid(x);r=sqrt(x.^2+y.^2)+eps;z=sin(r)./r;subplot(2,2,1)surf(x,y,z)xlabel('X-axis')ylabel('Y-axis')zlabel('Z-axis')title('Figure1')view(-37.5,30)subplot(2,2,2)surf(x,y,z)xlabel('X-axis')ylabel('Y-axis')zlabel('Z-axis')title('Figure2')view(-37.5+90,30) subplot(2,2,3)surf(x,y,z)xlabel('X-axis')ylabel('Y-axis')zlabel('Z-axis')title('Figure3')view(-37.5,60)subplot(2,2,4)surf(x,y,z)xlabel('X-axis')ylabel('Y-axis')zlabel('Z-axis')title('Figure4')view(180,0)实例24:向量场的绘制function shili24h0=figure('toolbar','none',...'position',[200 150 450 350],...'name','实例24');subplot(2,2,1)z=peaks;ribbon(z)title('Figure1')subplot(2,2,2)[x,y,z]=peaks(15);[dx,dy]=gradient(z,0.5,0.5); contour(x,y,z,10)hold onquiver(x,y,dx,dy)hold offtitle('Figure2')subplot(2,2,3)[x,y,z]=peaks(15);[nx,ny,nz]=surfnorm(x,y,z);surf(x,y,z)hold onquiver3(x,y,z,nx,ny,nz)hold offtitle('Figure3')subplot(2,2,4)x=rand(3,5);y=rand(3,5);z=rand(3,5);c=rand(3,5);fill3(x,y,z,c)grid ontitle('Figure4')实例25:灯光定位function shili25h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例25');vert=[1 1 1;1 2 1;2 2 1;2 1 1;1 1 2;12 2;2 2 2;2 1 2];fac=[1 2 3 4;2 6 7 3;4 3 7 8;15 8 4;1 2 6 5;5 6 7 8];grid offsphere(36)h=findobj('type','surface');set(h,'facelighting','phong',...'facecolor',...'interp',...'edgecolor',[0.4 0.4 0.4],...'backfacelighting',...'lit')hold onpatch('faces',fac,'vertices',vert,...'facecolor','y');light('position',[1 3 2]);light('position',[-3 -1 3]);material shinyaxis vis3d offhold off实例26:柱状图function shili26h0=figure('toolbar','none',...'position',[200 50 450 450],...'name','实例26'); subplot(2,1,1)x=[5 2 18 7 39 8 65 5 54 3 2];bar(x)xlabel('X轴');ylabel('Y轴');title('第一子图');subplot(2,1,2)y=[5 2 18 7 39 8 65 5 54 3 2];barh(y)xlabel('X轴');ylabel('Y轴');title('第二子图');实例27:设置照明方式function shili27h0=figure('toolbar','none',...'position',[200 150 450 350],...'name','实例27');subplot(2,2,1)sphereshading flatcamlight leftcamlight rightlighting flatcolorbaraxis offtitle('Figure1')subplot(2,2,2)sphereshading flatcamlight leftcamlight rightlighting gouraudcolorbaraxis offtitle('Figure2')subplot(2,2,3)sphereshading interpcamlight rightcamlight leftlighting phongaxis offtitle('Figure3')subplot(2,2,4)sphereshading flatcamlight leftcamlight rightlighting nonecolorbaraxis offtitle('Figure4')实例28:羽状图function shili28h0=figure('toolbar','none',...'position',[200 150 450 350],...'name','实例28');subplot(2,1,1)alpha=90:-10:0;r=ones(size(alpha));m=alpha*pi/180;n=r*10;[u,v]=pol2cart(m,n);feather(u,v)title('羽状图')axis([0 20 0 10])subplot(2,1,2)t=0:0.5:10;y=exp(-x*t);feather(y)title('复数矩阵的羽状图')实例29:立体透视(1)function shili29h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例29');[x,y,z]=meshgrid(-2:0.1:2,...-2:0.1:2,...-2:0.1:2);v=x.*exp(-x.^2-y.^2-z.^2);grid onfor i=-2:0.5:2;h1=surf(linspace(-2,2,20),...linspace(-2,2,20),...zeros(20)+i);rotate(h1,[1 -1 1],30)dx=get(h1,'xdata');dy=get(h1,'ydata');dz=get(h1,'zdata');delete(h1)slice(x,y,z,v,[-2 2],2,-2)hold onslice(x,y,z,v,dx,dy,dz)hold offaxis tightview(-5,10)drawnowend实例30:立体透视(2)function shili30h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例30');[x,y,z]=meshgrid(-2:0.1:2,...-2:0.1:2,...-2:0.1:2);v=x.*exp(-x.^2-y.^2-z.^2); [dx,dy,dz]=cylinder;slice(x,y,z,v,[-2 2],2,-2)for i=-2:0.2:2h=surface(dx+i,dy,dz);rotate(h,[1 0 0],90)xp=get(h,'xdata');yp=get(h,'ydata');zp=get(h,'zdata');delete(h)hold onhs=slice(x,y,z,v,xp,yp,zp);axis tightxlim([-3 3])view(-10,35)drawnowdelete(hs)hold offend实例31:表面图形function shili31h0=figure('toolbar','none',...'position',[200 150 550 250],...'name','实例31');subplot(1,2,1)x=rand(100,1)*16-8;y=rand(100,1)*16-8;r=sqrt(x.^2+y.^2)+eps;z=sin(r)./r;xlin=linspace(min(x),max(x),33); ylin=linspace(min(y),max(y),33); [X,Y]=meshgrid(xlin,ylin);Z=griddata(x,y,z,X,Y,'cubic'); mesh(X,Y,Z)axis tighthold onplot3(x,y,z,'.','Markersize',20) subplot(1,2,2)k=5;n=2^k-1;theta=pi*(-n:2:n)/n;phi=(pi/2)*(-n:2:n)'/n;X=cos(phi)*cos(theta);Y=cos(phi)*sin(theta);Z=sin(phi)*ones(size(theta)); colormap([0 0 0;1 1 1])C=hadamard(2^k);surf(X,Y,Z,C)axis square实例32:沿曲线移动的小球h0=figure('toolbar','none',...'position',[198****8468],...'name','实例32');h1=axes('parent',h0,...'position',[0.15 0.45 0.7 0.5],...'visible','on');t=0:pi/24:4*pi;y=sin(t);plot(t,y,'b')n=length(t);h=line('color',[0 0.5 0.5],...'linestyle','.',...'markersize',25,...'erasemode','xor');k1=uicontrol('parent',h0,...'style','pushbutton',...'position',[80 100 50 30],...'string','开始',...'callback',[...'i=1;',...'k=1;,',...'m=0;,',...'while 1,',...'if k==0,',...'break,',...'end,',...'if k~=0,',...'set(h,''xdata'',t(i),''ydata'',y(i)),',...'drawnow;,',...'i=i+1;,',...'if i>n,',...'m=m+1;,',...'i=1;,',...'end,',...'end,',...'end']);k2=uicontrol('parent',h0,...'style','pushbutton',...'position',[180 100 50 30],...'string','停止',...'callback',[...'k=0;,',...'set(e1,''string'',m),',...'p=get(h,''xdata'');,',...'q=get(h,''ydata'');,',...'set(e2,''string'',p);,',...'set(e3,''string'',q)']); k3=uicontrol('parent',h0,...'style','pushbutton',...'position',[280 100 50 30],...'string','关闭',...'callback','close');e1=uicontrol('parent',h0,...'style','edit',...'position',[60 30 60 20]);t1=uicontrol('parent',h0,...'style','text',...'string','循环次数',...'position',[60 50 60 20]);e2=uicontrol('parent',h0,...'style','edit',...'position',[180 30 50 20]);t2=uicontrol('parent',h0,...'style','text',...'string','终点的X坐标值',...'position',[155 50 100 20]);e3=uicontrol('parent',h0,...'style','edit',...'position',[300 30 50 20]);t3=uicontrol('parent',h0,...'style','text',...'string','终点的Y坐标值',...'position',[275 50 100 20]);实例33:曲线转换按钮h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例33');x=0:0.5:2*pi;y=sin(x);h=plot(x,y);grid onhuidiao=[...'if i==1,',...'i=0;,',...'y=cos(x);,',...'delete(h),',...'set(hm,''string'',''正弦函数''),',...'h=plot(x,y);,',...'grid on,',...'else if i==0,',...'i=1;,',...'y=sin(x);,',...'set(hm,''string'',''余弦函数''),',...'delete(h),',...'h=plot(x,y);,',...'grid on,',...'end,',...'end'];hm=uicontrol(gcf,'style','pushbutton',...'string','余弦函数',...'callback',huidiao);i=1;set(hm,'position',[250 20 60 20]);set(gca,'position',[0.2 0.2 0.6 0.6])title('按钮的使用')hold on实例34:栅格控制按钮h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例34');x=0:0.5:2*pi;y=sin(x);plot(x,y)huidiao1=[...'set(h_toggle2,''value'',0),',...'grid on,',...];huidiao2=[...'set(h_toggle1,''value'',0),',...'grid off,',...];h_toggle1=uicontrol(gcf,'style','togglebutton',...'string','grid on',...'value',0,...'position',[20 45 50 20],...'callback',huidiao1);h_toggle2=uicontrol(gcf,'style','togglebutton',...'string','grid off',...'value',0,...'position',[20 20 50 20],...'callback',huidiao2);set(gca,'position',[0.2 0.2 0.6 0.6])title('开关按钮的使用')实例35:编辑框的使用h0=figure('toolbar','none',...'position',[200 150 350 250],...'name','实例35');f='Please input the letter';huidiao1=[...'g=upper(f);,',...'set(h2_edit,''string'',g),',...];huidiao2=[...'g=lower(f);,',...'set(h2_edit,''string'',g),',...];h1_edit=uicontrol(gcf,'style','edit',...'position',[100 200 100 50],...'HorizontalAlignment','left',...'string','Please input the letter',...'callback','f=get(h1_edit,''string'');',...'background','w',...'max',5,...'min',1);h2_edit=uicontrol(gcf,'style','edit',...'HorizontalAlignment','left',...'position',[100 100 100 50],...'background','w',...'max',5,...'min',1);h1_button=uicontrol(gcf,'style','pushbutton',...'string','小写变大写',...'position',[100 45 100 20],...'callback',huidiao1);h2_button=uicontrol(gcf,'style','pushbutton',...'string','大写变小写',...'position',[100 20 100 20],...'callback',huidiao2);实例36:弹出式菜单h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例36');x=0:0.5:2*pi;y=sin(x);h=plot(x,y);grid onhm=uicontrol(gcf,'style','popupmenu',...'string',...'sin(x)|cos(x)|sin(x)+cos(x)|exp(-sin(x))',...'position',[250 20 50 20]);set(hm,'value',1)huidiao=[...'v=get(hm,''value'');,',...'switch v,',...'case 1,',...'delete(h),',...'y=sin(x);,',...'h=plot(x,y);,',...'grid on,',...'case 2,',...'delete(h),',...'y=cos(x);,',...'h=plot(x,y);,',...'grid on,',...'case 3,',...'delete(h),',...'y=sin(x)+cos(x);,',...'h=plot(x,y);,',...'grid on,',...'case 4,',...'delete(h),',...'y=exp(-sin(x));,',...'h=plot(x,y);,',...'grid on,',...'end'];set(hm,'callback',huidiao)set(gca,'position',[0.2 0.2 0.6 0.6]) title('弹出式菜单的使用')实例37:滑标的使用h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例37');[x,y]=meshgrid(-8:0.5:8);r=sqrt(x.^2+y.^2)+eps;z=sin(r)./r;h0=mesh(x,y,z);h1=axes('position',...[0.2 0.2 0.5 0.5],...'visible','off');htext=uicontrol(gcf,...'units','points',...'position',[20 30 45 15],...'string','brightness',...'style','text');hslider=uicontrol(gcf,...'units','points',...'position',[10 10 300 15],...'min',-1,...'max',1,...'style','slider',...'callback',...'brighten(get(hslider,''value''))'); 实例38:多选菜单h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例38');[x,y]=meshgrid(-8:0.5:8);r=sqrt(x.^2+y.^2)+eps;z=sin(r)./r;h0=mesh(x,y,z);hlist=uicontrol(gcf,'style','listbox',...'string','default|spring|summer|autumn|winter',...'max',5,...'min',1,...'position',[20 20 80 100],...'callback',[...'k=get(hlist,''value'');,',...'switch k,',...'case 1,',...'colormap default,',...'case 2,',...'colormap spring,',...'case 3,',...'colormap summer,',...'case 4,',...'colormap autumn,',...'case 5,',...'colormap winter,',...'end']);实例39:菜单控制的使用h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例39');x=0:0.5:2*pi;y=cos(x);h=plot(x,y);grid onset(gcf,'toolbar','none')hm=uimenu('label','example');huidiao1=[...'set(hm_gridon,''checked'',''on''),',...'set(hm_gridoff,''checked'',''off''),',...'grid on'];huidiao2=[...'set(hm_gridoff,''checked'',''on''),',...'set(hm_gridon,''checked'',''off''),',...'grid off'];hm_gridon=uimenu(hm,'label','grid on',...'checked','on',...'callback',huidiao1);hm_gridoff=uimenu(hm,'label','grid off',...'checked','off',...'callback',huidiao2);实例40:UIMENU菜单的应用h0=figure('toolbar','none',...'position',[200 150 450 250],...'name','实例40');h1=uimenu(gcf,'label','函数');h11=uimenu(h1,'label','轮廓图',...'callback',[...'set(h31,''checked'',''on''),',...'set(h32,''checked'',''off''),',...'[x,y,z]=peaks;,',...'contour3(x,y,z,30)']);h12=uimenu(h1,'label','高斯分布',...'callback',[...'set(h31,''checked'',''on''),',...'set(h32,''checked'',''off''),',...'mesh(peaks);,',...'axis tight']);。

第三章 matlab图形绘制

第三章 matlab图形绘制
gtext 用于在图形中特定的位置加字符串,位置用鼠标
指定
grid 图形中加网格
例3.在同一坐标系下画出sinx和cosx的图形,并适当加 标注.
x=linspace(0,2*pi,30);y=[sin(x);cos(x)]; plot(x,y);grid;xlabel (‘x’);ylabel (‘y’); title(‘sine and cosine curves’); text(3*pi/4,sin(3*pi/4),’\leftarrowsinx’); text(2.55*pi/2,cos(3*pi/2),’cos\rightarrow’)
结果见下图.
4.多幅图形
subplot(m,n,p)可以在同一个图形窗口中画出多个图 形,用法见下例.
x=linspace(0,2*pi,30);y=sin(x);z=cos(x);u=2*sin(x).* cos(x);v=sin(x)./cos(x); subplot(2,2,1),plot(x,y),title(‘sin(x)’) subplot(2,2,2),plot(x,z),title(‘cos(x)’) subplot(2,2,3),plot(x,u),title(‘2sin(x)cos(x)’) subplot(2,2,4),plot(x,v),title(‘sin(x)/cos(x)’)
plot(x1,y1,x2,y2, …) 在此格式中,每对x,y必须符合 plot(x,y)中的要求,不同对之间没有影响,命令对每 一对x,y绘制曲线.
例1.做出y=sinx在[0,2π]上的图形,结果见下图.
x=linspace(0,2*pi,30); sin(x);plot(x,y)
例2.在同一坐标系下做出两条曲线y=sinx和y=cosx 在[0,2π]上的图形.结果见下图.

第二章 MATLAB绘图

第二章  MATLAB绘图

说明:
(1)当x,y是同维矩阵时,则以x,y对应列元素为
横、纵坐标分别绘制曲线,曲线条数等于矩阵
的列数。 (2)当x是向量,y是有一维与x同维的矩阵时, 则绘制出多根不同色彩的曲线。曲线条数等于 y矩阵的另一维数,x被作为这些曲线共同的横
坐标。
(3)plot函数最简单的调用格式是只包含一个输 入参数:plot(x)。
对图形窗口灵活分割。请看下面的程序。
x=linspace(0,2*pi,60);
y=sin(x);z=cos(x);
t=sin(x)./(cos(x)+eps); ct=cos(x)./(sin(x)+eps); subplot(2,2,1); stairs(x,y); title('sin(x)-1');axis ([0,2*pi,-1,1]); %选择2×2个区中的1号区
2.2.1绘制三维曲线的最基本函数 plot3函数与plot函数用法十分相似,其调用格式为: plot3(x1,y1,z1,选项1,x2,y2,z2,选项2,…,xn,yn,zn,选项n)
4. 对函数自适应采样的绘图函数
fplot函数的调用格式为: fplot(fname,lims,tol,选项) 例2.11 用fplot函数绘制f(x)=cos(tan(πx))的曲线。 先建立函数文件myf.m: function y=myf(x) y=cos(tan(pi*x));
再用fplot函数绘制myf.m函数的曲线:
例2.6 用图形保持功能在同一坐标内绘制曲线
y=2e-0.5xsin(2πx)及其包络线,并加网格线。
程序如下: x=(0:pi/100:2*pi)'; y1=2*exp(-0.5*x)*[1,-1];y2=2*exp(-0.5*x).*sin(2*pi*x); plot(x,y1,'b:'); axis([0,2*pi,-2,2]); %设置坐标 hold on; %设置图形保持状态 plot(x,y2,'k'); grid on; %加网格线 box off; %不加坐标边框 hold off; %关闭图形保持

Matlab基础及其应用 第4章 图形绘制

Matlab基础及其应用 第4章 图形绘制
%设置曲线标记为圆
'MarkerIndices',[1 31 61 91 121],... %在4个点显示标记
'MarkerEdgeColor','r',...
%设置曲线标记外框为红色
'MarkerFaceColor','y',...
%设置曲线标记内填充黄色
'MarkerSize',8)
%设置曲线标记大小为8
用法:
fplot(funx, funy, lims)
其中,funx、funy代表函数,通常采用函数句柄的形式。li
ms为参数函数funx和funy的自变量的取值范围,用二元向量
[tmin,tmax]描述。例如,例4.1也可以用以下命令实现:
>> fplot(@(t)sin(t)+sin(2*t), @(t)cos(t)-cos(2*t), [0,2*pi])
t1=linspace(0,3*pi,90);
x=cos(t1)+t1.*sin(t1);
t2=linspace(0,2*pi,50);
y=sin(t2)-t2.*cos(t2);
plot(t1,x,t2,y);
4.1 二维曲线的绘制
MATLAB基础与应用教程
4.1.1 绘制二维曲线
2.fplot函数
支持的TeX字符串中,用\bf、\it、\rm标识符分别定义字形
为加粗、倾斜和常规字体。
表4.5中的各个字符既可以单独使用,又可以和其他字符及
命令联合使用。为了将控制字符串、TeX标识符与输出字符
分隔开来,可以用大括号界定控制字符串以及受控制字符串

matlab图像处理基础实例

matlab图像处理基础实例

matlab图像处理基础实例·边缘检测(edge)边缘检测时先要把其他格式图像转化为灰度图像>> f=imread('');>> a=rgb2gray(f);>> [g,t]=edge(a,'canny');>> imshow(g)·剪贴(imcrop)、subplot等imfinfo colormap subimageimadd imsubtract immultiply imdivide imresize imrotate(旋转)>> a=imread('');>> b=imcrop(a,[75 68 130 112]);% I2 = IMCROP(I,RECT)% RECT is a 4-element vector with the form [XMIN YMIN WIDTH HEIGHT]; % subplot(121)⼀⾏两列的显⽰,当前显⽰第⼀个图⽚>> subplot(121);imshow(a);>> subplot(122);imshow(b);·roipoly选择图像中的多边形区域>> a=imread('');>> c=[200 250 278 248 199 172];>> r=[21 21 75 121 121 75];>> b=roipoly(a,c,r);>> subplot(121);imshow(a);>> subplot(122);imshow(b);·roicolor按灰度值选择的区域>> a=imread('');>> i=rgb2gray(a);>> b=roicolor(i,128,255);>> subplot(121);imshow(a);>> subplot(122);imshow(b);·转化指定的多边形区域为⼆值掩膜poly2mask>> x=[63 186 54 190 63];>> y=[60 60 209 204 60];>> b=poly2mask(x,y,256,256); >> imshow(b);>> holdCurrent plot held>> plot(x,y,'b','LineWidth',2)·roifilt2区域滤波a=imread('');i=rgb2gray(a);c=[200 250 278 248 199 172];r=[21 21 75 121 121 75];b=roipoly(i,c,r);h=fspecial('unsharp');j=roifilt2(h,i,b);subplot(121),imshow(i);subplot(122),imshow(j);·roifill区域填充>> a=imread('');>> i=rgb2gray(a);>> c=[200 250 278 248 199 172]; >> r=[21 21 75 121 121 75]; >> j=roifill(i,c,r); >> subplot(211);imshow(i);>> subplot(212);imshow(j);·FFT变换f=zeros(100,100);f(20:70,40:60)=1;imshow(f);F=fft2(f);F2=log(abs(F));imshow(F2),colorbar·补零操作和改变图像的显⽰象限f=zeros(100,100);f(20:70,40:60)=1;subplot(121);imshow(f);F=fft2(f,256,256);F2=fftshift(F);subplot(122);imshow(log(abs(F2)))·离散余弦变换(dct)>> a=imread('');>> i=rgb2gray(a);>> j=dct2(i);>> subplot(131);imshow(log(abs(j))),colorbar >> j(abs(j)<10)=0;>> k=idct2(j);>> subplot(132);imshow(i);>> subplot(133);imshow(k,[0,255]);info=imfinfo('')%显⽰图像信息·edge提取图像的边缘canny prewitt sobelradon函数⽤来计算指定⽅向上图像矩阵的投影>> a=imread('');>> i=rgb2gray(a);>> b=edge(i);>> theta=0:179;>> [r,xp]=radon(b,theta);>> figure,imagesc(theta,xp,r);colormap(hot); >> xlabel('\theta(degrees)'); >> ylabel('x\prime');>> title('r_{\theta}(x\prime)');>> colorbar·filter2均值滤波>> a=imread('');>> i=rgb2gray(a);>> imshow(i)>> k1=filter2(fspecial('average',3),i)/255;%3*3 >> k2=filter2(fspecial('average',5),i)/255;%5*5 >> k3=filter2(fspecial('average',7),i)/255;%7*7 >> figure,imshow(k1)>> figure,imshow(k2)>> figure,imshow(k3)wiener2滤波eg:k=wiener(I,[3,3]))medfilt2中值滤波同上deconvwnr维纳滤波马赫带效应(同等差⾊带条)·减采样>> a=imread('');>> b=rgb2gray(a);>> [wid,hei]=size(b);>> quarting=zeros(wid/2+1,hei/2+1); >> i1=1;j1=1;>> for i=1:2:widfor j=1:2:heiquarting(i1,j1)=b(i,j);j1=j1+1;endi1=i1+1;j1=1;end>> figure>> imshow(uint8(quarting))>> title('4倍减采样')>> quarting=zeros(wid/4+1,hei/4+1); i1=1;j1=1;for i=1:4:widfor j=1:4:heiquarting(i1,j1)=b(i,j);j1=j1+1;endi1=i1+1;j1=1;end>> figure,imshow(uint8(quarting)); title('16倍减采样')结论:在采⽤不同的减采样过程中,其图像的清晰度和尺⼨均发⽣了变化灰度级转化>> a=imread('');>> b=rgb2gray(a);>> figure;imshow(b)>> [wid,hei]=size(b);>> img2=zeros(wid,hei);>> for i=1:widfor j=1:heiimg2(i,j)=floor(b(i,j)/128);endend>> figure;imshow(uint8(img2),[0,2]) %2级灰度图像图像的基本运算>> i=imread('');>> figure;subplot(231);imshow(i);>> title('原图');>> j=imadjust(i,[.3;.6],[.1 .9]);%Adjust image intensity values or colormap图像灰度值或colormap调整% J = IMADJUST(I,[LOW_IN; HIGH_IN],[LOW_OUT; HIGH_OUT])>> subplot(232);imshow(j);title('线性扩展');>> i1=double(i);i2=i1/255;c=2;k=c*log(1+i2);>> subplot(233);imshow(k);>> title('⾮线性扩展');>> m=255-i;>> subplot(234);imshow(m)>> title('灰度倒置')>> n1=im2bw(i,.4);n2=im2bw(i,.7);>> subplot(235);imshow(n1);title('⼆值化阈值')>> subplot(236);imshow(n2);title('⼆值化阈值')图像的代数运算加。

MATLAB图像处理实例详解

MATLAB图像处理实例详解
%关闭所有图形窗口,清除工作空间所有变量,清空命令行 %创建 S1 字符串 %创建 S2 字符串 %合并字符数组 %连接字符串 S1 和 S2 %横向连接字符串 S1 和 S2 %纵向连接字符串 S1 和 S2 %拆分截取字符串 S2
%关闭所有图形窗口,清除工作空间所有变量,清空命令行
1
MATLAB 图像处理实例详解
close all; clear all; clc;
%关闭所有图形窗口,清除工作空间所有变量,清空命令行
stu(1).name='LiMing';
%直接创建结构体 stu
stu(1).number='20120101';
stu(1).sex='f';
stu(1).age=20;
stu(2).name='WangHong';
MATLAB
图像处理实例详解
——程序部分
MATLAB 图像处理实例详解
目录
第 2 章 MATLAB 基础 ....................................................................................................................1 第 3 章 MATLAB 图像处理基础 ..................................................................................................11 第 4 章 数字图像的运算.............................................................................................................18 第 5 章 图像增强技术.................................................................................................................33 第 6 章 图像复原技术.................................................................................................................39 第 7 章 图像分割技术.................................................................................................................44 第 8 章 图像变换技术.................................................................................................................46 第 9 章 彩色图像处理.................................................................................................................54 第 10 章 图像压缩编码...............................................................................................................55 第 11 章 图像特征分析...............................................................................................................69 第 12 章 形态学图像处理.........................................................................................................103 第 13 章 小波在图像处理中的应用.........................................................................................106 第 14 章 基于 SIMULINK 的视频和图像处理...........................................................................117 第 15 章 图像处理的 MATLAB 实例 .........................................................................................120

Matlab绘图教程(大量实例PPT)

Matlab绘图教程(大量实例PPT)

MATLAB绘图二维数据曲线图pplot函数的基本调用格式为:x,y) )plot(plot(x,y其中x和y为长度相同的向量,分别用于存储x坐标和y坐标数据。

数据例1 在0≤x2π区间内,绘制曲线y=2e-0.5x cos(4πx)1≤区间内绘制曲线205x(4)程序如下:x=0:pi/100:2*pi;cos(4*pi*x);0.5*x).*cos(4*pi*x);y=2*exp(--0.5*x).*y=2*exp(x,y))plot(x,yplot(x yplot(x y)例2 绘制曲线。

绘制曲线程序如下:t=0:0.1:2*pi;x=t.sin(3t);x=t*sin(3*t);y=t.*sin(t).*sin(t); plot(x,y););plot(x,y数最简单的调用格式是包含个输参数plot函数最简单的调用格式是只包含一个输入参数:p()plot(x)在这种情况下,当x是实向量时,以该向量元素的下标为横坐标,元素值为纵坐标画出条连续曲线,标为横坐标,元素值为纵坐标画出一条连续曲线,这实际上是绘制折线图。

绘制多根二维曲线1.plot函数的输入参数是矩阵形式时数的输参数是矩阵形式时(1) 当x是向量,y是有一维与x同维的矩阵时,则绘制出多根不同颜色的曲线。

曲线条数等于y矩阵的另一维数,x被作为这些曲线共同的横坐标。

(2) 当x,y是同维矩阵时,则以x,y对应列元素为横、纵坐标分别绘制曲线,曲线条数等于矩阵的列数。

纵坐标分别绘制曲线曲线条数等于矩阵的列数(3) 对只包含一个输入参数的plot函数,当输入参数对包含个输参数的数当输参数是实矩阵时,则按列绘制每列元素值相对其下标的曲线曲线条数等于输入参数矩阵的列数的曲线,曲线条数等于输入参数矩阵的列数。

当输入参数是复数矩阵时,则按列分别以元素实部和虚部为横、纵坐标绘制多条曲线。

2.含多个输入参数的plot函数含多个输参数的数调用格式为:plot(x1,y1,x2,y2,…,xn,yn)(1) 当输入参数都为向量时,x1和y1,x2和y2,…,(1)当输入参数都为向量时xn和yn分别组成一组向量对,每一组向量对的长度可以不同每一向量对可以绘制出一条曲线度可以不同。

matlab基础作图实例

matlab基础作图实例

实验三 MATLAB 的绘图一、实验目的:掌握利用MATLAB 画曲线和曲面。

二、实验容:1、 在不同图形中绘制下面三个函数t ∈[0,4π]的图象,3个图形分别是figure(1),figure(2),figure(3)。

)sin(41.0321t e y ty t y t -===π说明:y 1 线型:红色实线,y 2 线型:黑色虚线,y 3: 线型:兰色点线 分别进行坐标标注,分别向图形中添加标题‘函数1’,‘函数2’, ‘函数3’ 解答:源程序与图像: t=0:0.1:4*pi; y_1=t;y_2=sqrt(t);y_3=4*pi.*exp(-0.1*t).*sin(t); figure(1)plot(t,y_1,'-r'); title('函数1');xlabel('t');ylabel('y_1'); figure(2)plot(t,y_2,'--k'); title('函数2');xlabel('t');ylabel('y_2'); figure(3)plot(t,y_3,':b'); title('函数3');xlabel('t');ylabel('y_3');函数1ty1函数2t y2函数3ty32、 在同一坐标系下绘制下面三个函数在t ∈[0,4π]的图象。

(用2种方法来画图,其中之一使用hold on ) 使用text 在图形适当的位置标注“函数1”“函数2”,“函数3” 使用gtext 重复上面的标注,注意体会gtext 和text 之间的区别 解答: 方法一: 程序与图形: t=0:0.1:4*pi; y_1=t;y_2=sqrt(t);y_3=4*pi.*exp(-0.1*t).*sin(t); figure(1)plot(t,y_1,'-r'); gtext('函数1');xlabel('t');ylabel('y'); hold onplot(t,y_2,'--k'); gtext('函数2');hold onplot(t,y_3,':b'); gtext('函数3');2468101214-10-5051015ty方法二:t=0:0.1:4*pi; y_1=t;y_2=sqrt(t);y_3=4*pi.*exp(-0.1*t).*sin(t); figure(1)plot(t,y_1,'-r',t,y_2,'--k',t,y_3,':b'); xlabel('t');ylabel('y'); text(10,10,'函数1'); text(11,2,'函数2'); text(11,-5,'函数3');02468101214-10-551015ty4、绘制ρ=sin(2θ)cos(2θ)的极坐标图源程序和图形:theta=0:pi/100:2*pi;rho=sin(2*theta).*cos(2*theta); polar(theta,rho);902705、绘制y=10x2的对数坐标图并与直角线性坐标图进行比较。

实验三 MATLAB绘图(含实验报告)

实验三 MATLAB绘图(含实验报告)

实验三 MATLAB 绘图一、实验目的1.掌握二维图形的绘制。

2.掌握图形的标注3.了解三维曲线和曲面图形的绘制。

二、实验的设备及条件计算机一台(带有以上的软件环境)。

设计提示1.Matlab 允许在一个图形中画多条曲线:plot(x1,y1,x2,y2,……)指令绘制y 1 = f 1(x 1), y 2 = f 2 (x 2 )等多条曲线。

Matlab 自动给这些曲线以不同颜色。

标注可用text 函数。

2.绘图时可以考虑极坐标和直角坐标的转换。

3.三维曲线绘图函数为plot3,注意参考帮助中的示例。

三、实验内容1.生成1×10 维的随机数向量a ,分别用红、黄、蓝、绿色绘出其连线图、杆图、阶梯图和条形图,并分别标出标题“连线图”、“杆图”、“阶梯图”、“条形图”。

2、绘制函数曲线,要求写出程序代码。

(1) 在区间[0:2π]均匀的取50个点,构成向量t(2) 在同一窗口绘制曲线y1=sin(2*; y2=3cos(t+;要求y1曲线为红色点划线,标记点为圆圈;y2为蓝色虚线,标记点为星号。

(3) 分别在靠近相应的曲线处标注其函数表达式。

3.将图形窗口分成两个绘图区域,分别绘制出函数:⎩⎨⎧+-=+=1352221x x y x y 在[0,3]区间上的曲线,并利用axis 调整轴刻度纵坐标刻度,使1y 在[0,12]区间上,2y 在[-2,]区间上。

4.用mesh 或surf 函数,绘制下面方程所表示的三维空间曲面,x 和y 的取值范围设为[-3,3]。

101022y x z +-=思考题:1. 编写一个mcircle(r)函数,调用该函数时,根据给定的半径r ,以原点为圆心,画一个如图所示的红色空心圆。

(图例半径r=5);左图参考polar函数的用法,右图绘制圆形的参数方程为x=sin (t ),y=cos (t )。

其中,t 的区间为0~2*pi ,步长为。

2.(1)绘一个圆柱螺旋线(形似弹簧)图。

matlab 函数作图

matlab 函数作图

03 函数作图1 平面图形(1)竖直条形图调用格式为:bar(x,y)(2)用描点法绘制函数y f ( x) 随x 从a 到b 间的图形.调用格式为:x=a:h:b ;y=f(x) ;plot(x,y)(3)在同一坐标系下绘制多个函数图形.调用格式为:x=a:h:b ;plot(x,y1,x,y2,…)(4)绘制函数y=f(x)随x 从a 到b 间的图形.调用格式为:explo t(‘f(x)’, [a,b])(5)x 从xa 到xb和y 从ya到yb间隐函数 f ( x, y) 0 的图形.调用格式为:ezplo t(‘x’,’y’,[xa, x b , y a , y b ])(6)绘制t 从ta 到tb间参数方程x x(t ),y y(t )的函数图形.调用格式为:ezplo t(‘x’,’y’,[ta, t b ])(7)在一坐标系下可以绘制一个或多个显函数图形,对变化剧烈的函数,用此命令来进行较精确的绘画.调用格式为:fplot(’fun(x)’,[a,b])fplo t (‘[f1(x),f2(x),…]’,[a,b])其中fun(x)可以是自定义函数,[f1(x),f2(x),…]是函数组.(8)绘制散点图.调用格式为:scatter(x,y)2 空间图形(1)空间曲线.调用格式为:plot3(x,y,z)(2)产生一个以向量x 为行,向量y 为列的矩阵.调用格式为:meshgrid(x,y)(3)空间曲面.调用格式为:surf(x,y,z)(4)网格曲面.调用格式为:mesh(x,y,z)例 1 一次考试成绩0~10 分有0 人,10~20 分有0 人,20~30 分1 人,30~40 分有1 人,50~60 分有2 人,60~70 分有18 人,70~80 分有20 人,80~90 分有9 人,90~100 分有6 人.绘出成绩分析竖直条形图.【matlab 命令】>> x=0:10:90;>> y=[0,0,1,1,0,2,18,20,9,6];>> bar(x,y)【输出结果】20002图1例1输出图像例 2 绘制显函数图形.x(1)设 y 1x 3 2x , y2000 cos2sin x请分别作出这两个函数在区间 x[20,40] 的图像,然后将它们的图像在一个平面直角坐标系中,并判断方程 y 1x 3 2 x 1500cos x2sin x 有几个实数解.(2)在 x[0,4] 上画出分段函数方法一:【matlab 命令】>> x=-20:0.1:40;>> y1=x.^3-35*x.^2+100*x+1500; >> y2=2000*(cos(x/2)-sin(x)); >> figure(1)>> plot(x,y1,'b-'); >> figure(2) >> plot(x,y2,'k');f ( x )32 x 2x 20 x 2 x 2的图像>> figure(3)>> plot(x,y1,'b-',x,y2,'k')【输出结果】图2例2(1)函数y1图3 例 2(1)函数 y 2 输出图像图4例 2(1)函数 y 1 和 y 2 输出图像 从图中知:有 7 个交点,也就是有 7 个实数根.说明:绘制图形着色时,g 表示绿色,r 表示红色,b 表示蓝色,k 表示黑色.方法二:【matlab 命令2】%自定义函数M文件fx1 function y1=fx1(x)y1=x^3-35*x.^2+100*x+1500%自定义函数M文件fx2 function y2=fx2(x)y2=2000*(cos(x/2)-sin(x));Matlab命令窗口输入以下命令: >> figure(1)>> fplot('fx1(x)',[-20,40]); >> figure(2)>> fplot('fx2(x)',[-20,40]); >> figure(3)>> fplot('[fx1(x) , fx2(x)] ', [-20,40]); 【输出结果2】结果同上.【matlab 命令3】>> x=0:0.01:2;>> y=(2*x-x.^2).^(1/3);>> plot(x,y,'k','linewidth',2)>> hold on>> x=2:0.01:4;>> y=x-2;>> plot(x,y,'k','linewidth',2)【输出结果3】图5例2(2)函数f(x)的输出图像例3绘制隐函数和参数方程所确定函数的图形.(1)在x [3,3] 上画隐函数x 2 2 9 的图像.(2)在t [0,2] 上画参数方程x cos3 t ,y sin 3 t 的图像.【matlab 命令1】>> ezplot('x^2+y^2-9',[-3,3])>> axis equal【输出结果1】图6例3(1)输出图像说明:axis on 显示坐标轴,axis off 取消坐标轴,grid on 表示加网格线,grid off 表示不加网格线,clf 清楚图形窗口中的图形.也可以通过编辑图像的方法改变或增加设置,比如在图形窗口中,菜单栏Tools中鼠标选中Edit-Plot,可改变图像的颜色.【matlab 命令2】>> ezplot('cos(t)^3','sin(t)^3',[0,2*pi])【输出结果2】图7例3(2)输出图像例4将图4,5,6,7在同一个图形窗口表现出来.【matlab 命令】clfsubplot(2,2,1)x=-20:0.1:40;y1=x.^3-35*x.^2+100*x+1500;y2=2000*(cos(x/2)-sin(x));plot(x,y1,'b-',x,y2,'k');subplot(2,2,2)x=0:0.01:2;y=(2*x-x.^2).^(1/3);plot(x,y) holdon x=2:0.01:4;y=x-2;plot(x,y)subplot(2,2,3)ezplot('x^2+y^2-9',[-3,3])axis equal subplot(2,2,4)ezplot('cos(t)^3','sin(t)^3',[0,2*pi])【输出结果】图8 例4输出图像例5已知平面内8个散点的坐标(1,15,2,20(3,27(4,36(5,49,(6,65(7,87(8,117,在直角坐标系中绘制点图.【matlab 命令】 clf x=1:8; y=[15.3,20.5,27.4,36.6,49.1,65.6,87.8,117.6]; scatter(x,y,'ko') 【输出结果】图9例6 在区间[0,10] 上画出参数曲线x sin t, y cos t, z t .【matlab 命令】clft=0:pi/50:10*pi;plot3(sin(t),cos(t),t)【输出结果】图10例7画函数Z ( X Y) 2 的图形.【matlab 命令】clfx=-3:0.1:3; y=1:0.1:5;[X,Y]=meshgrid(x,y);Z=(X+Y).^2;surf(X,Y,Z)shading flat【输出结果】图11例8画出马鞍曲面Z X 2 Y2 在不同视角的网格图.【matlab 命令】clfx=-3:0.1:3; y=1:0.1:5;[X,Y]=meshgrid(x,y);Z=X.^2-Y.^2;mesh(X,Y,Z)【输出结果】图123 习题1.某城市一年12个月的日平均气温(单位: 0C )分别为:-10,-6,5,10,20,25,30,24,22,19,10,6,试画出条形图. 2.作出函数 f ( x )cos(e x ) e x / 2) 在区间 x [4,4] 的图形3.作隐函数 sin( xy ) 0 在 [6,6] 内的图形.cos x 2 x 2 4.已知分段函数 y x x 1 ,作出 15 x 15 的函数图形. 2 sin( x 1) 1x 15.在同一直角坐标系中,作出函数 y5 的图形和函数 x 3 的图形.6.已知sin( x 2 2 )7.绘制空间图形:(墨西哥帽子).x 2 2。

matlab 三维图形绘制实例(完整资料).doc

matlab  三维图形绘制实例(完整资料).doc

【最新整理,下载后即可编辑】三维图形一.三维曲线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对应列元素绘制三维曲线,曲线条数等于矩阵列数。

Example1.绘制三维曲线。

程序如下:clf,t=0:pi/100:20*pi;x=sin(t);y=cos(t);z=t.*sin(t).*cos(t); %向量的乘除幂运算前面要加点plot3(x,y,z);title('Line in 3-D Space');xlabel('X');ylabel('Y');zlabel('Z');grid on;所的图形如下:XLine in 3-D SpaceYZ二. 三维曲面 1. 产生三维数据 在MATLAB 中,利用meshgrid 函数产生平面区域内的网格坐标矩阵。

语句执行后,矩阵X 的每一行都是向量x ,行数等于向量y 的元素的个数,矩阵Y 的每一列都是向量y ,列数等于向量x 的元素的个数。

2. 绘制三维曲面的函数surf 函数和mesh 函数example2. 绘制三维曲面图z=sin(x+sin(y))-x/10。

程序如下: clf,[x,y]=meshgrid(0:0.25:4*pi); %产生平面坐标区域内的网格坐标矩阵z=sin(x+sin(y))-x./10; surf(x,y,z);axis([0 4*pi 0 4*pi -2.5 1]);title('surf 函数所产生的曲面'); figure;mesh(x,y,z);axis([0 4*pi 0 4*pi -2.5 1]);title('mesh 函数所产生的曲面');-2.5-2-1.5-1-0.500.51surf 函数所产生的曲面-2.5-2-1.5-1-0.500.51mesh 函数所产生的曲面Example3.绘制4种三维曲面图。

MATLAB中绘图命令介绍

MATLAB中绘图命令介绍

MATLAB中绘图命令介绍本节将介绍MATLAB基本xy平面及xyz空间的各项绘图命令,包含一维曲线及二维曲面的绘制。

plot是绘制一维曲线的基本函数,但在使用此函数之前,我们需先定义曲线上每一点的x 及y座标。

下例可画出一条正弦曲线:close all;x=linspace(0, 2*pi, 100); % 100个点的x坐标y=sin(x); % 对应的y坐标plot(x,y);小整理:MATLAB基本绘图函数plot: x轴与y轴均为线性刻度(Linear scale)loglog: x轴与y轴均为对数刻度(Logarithmic scale)semilogx: x轴为对数刻度,y轴为线性刻度semilogy: x轴为线性刻度,y轴为对数刻度若要画出多条曲线,只需将座标对依次放入plot函数即可:hold on 保持当前图形,以便继续画图到当前坐标窗口hold off 释放当前图形窗口title(’图形名称’)(都放在单引号内)xlabel(’x轴说明’)ylabel(’y轴说明’)text(x,y,’图形说明’)legend(’图例1’,’图例2’,…)plot(x, sin(x), x, cos(x));若要改变颜色,在座标对後面加上相关字串即可:plot(x, sin(x), 'c', x, cos(x), 'g');若要同时改变颜色及图线型态,也是在座标对後面加上相关字串即可:plot(x, sin(x), 'co', x, cos(x), 'g*');小整理:plot绘图函数的叁数字元、颜色元、图线型态,y 黄色 .点k 黑色o 圆w 白色x xb 蓝色++g 绿色* *r 红色- 实线c 亮青色: 点线m锰紫色-. 点虚线-- 虚线plot3 三维曲线作图图形完成后,我们可用axis([xmin,xmax,ymin,ymax])函数来调整图轴的范围: axis([0, 6, -1.2, 1.2]);axis函数的功能丰富,其常用的用法有:axis equal :纵横坐标轴采用等长刻度axis square:产生正方形坐标系(默认为矩形)axis auto:使用默认设置axis off:取消坐标轴axis on :显示坐标轴此外,MATLAB也可对图形加上各种注解与处理:xlabel('Input Value'); % x轴注解ylabel('Function Value'); % y轴注解title('Two Trigonometric Functions'); % 图形标题legend('y = sin(x)','y = cos(x)'); % 图形注解grid on; % 显示格线我们可用subplot来同时画出数个小图形於同一个视窗之中:subplot(2,2,1); plot(x, sin(x));subplot(2,2,2); plot(x, cos(x));subplot(2,2,3); plot(x, sinh(x));subplot(2,2,4); plot(x, cosh(x));MATLAB还有其他各种二维绘图函数,以适合不同的应用,详见下表。

MATLAB第二章

MATLAB第二章

function [egg1,egg2,chicken1]=myegg(n)
% egg1 隔1天的蛋个数 % egg2 隔2天的蛋个数 % chicken1 过n天后母鸡个数 if n==1
egg1=1; egg2=0; chicken1=1; elseif n==2 egg1=1; egg2=1; chicken1=1;
27
>> x=0:0.1:2*pi; >> y=sin(x); >> plot(x,y) >> plot(x,y,‘ro’) %默认是蓝色曲线 >> x=[0 1 2 5];y=[4 -2 1 2]; >> plot(x,y) >> fplot(‘x^2+4*x+1’,[-15 15]) %函数用字符串表示
1 -8 4 9 -4 5 7 -9 >> fun=@myfun5 %例28中的函数 fun =
@myfun5 >> y=fun(A) %直接调用 y=
1 -13 16 81 -5 25 49 -15 >> y=feval(fun,A) %利用feval y=
1 -13 16 81 -5 25 49 -15
1 4 9 16 5 10 15 20
2024/7/5
第二章 MATLAB编程与作图
24
>> k=5;
>> ff=@(x)x^2+2*x+k %可以使用空间中的变量k
ff =
@(x)x^2+2*x+k
>> ff(5)
ans =
40
>> A=[1 2 ;3 4]

matlab中plot基础绘图实例

matlab中plot基础绘图实例

%plot基本绘图x=0:0.1:2*pi;y=sin(x)plot(x,y)%两个参数都是矩阵x1=0:0.1:2*pi;x2=-pi:0.1:pi;y1=sin(x)y2=cos(x)plot(x1,y1,x2,y2)%多条曲线绘制在统一坐标轴上%plot只有一个参数x=linspace(0,2*pi,200)y=sin(x)plot(y)y2=cos(x)y3=y+i*y2%横坐标实部为正弦,纵坐标虚部为余弦,构成一个圆形plot(y3)axis equal%将上述图型的横纵坐标调整为相同,使得椭圆变为正圆%plot含有多个参数x1=linspace(0,2*pi,200)x2=linspace(0,2*pi,100)x3=linspace(0,2*pi,50)y1=cos(x1)y2=sin(x2)y3=0.01*exp(x3)plot(x1,y1,x2,y2,x3,y3)%当x1,x2,x3不同维数(点数不同)可用高方法绘制%线性选项x=0:0.1:2*pi;y=sin(x)plot(x,y,'r')%颜色,g为绿色,y为黄色,k为黑色,默认b为蓝色plot(x,y,'*')%形状,*为*状,p为五角星,.为小方块plot(x,y,'--')%--为短线,:为虚线,-.为点虚线plot(x,y,'*r--')%可以组合使用,只需用一对单引号把要求全部括起来%标注x=0:0.1:2*pi;y=sin(x)plot(x,y)xlabel('x')%横坐标轴名称ylabel('y')%纵坐标轴名称title('正弦')%图名text(2,0.2,'正弦函数')%在坐标(2,0.2)处文本标注,如果同一文件下含有text.m文件,则报错%图例x1=0:0.1:2*pi;x2=-pi:0.1:pi;y1=sin(x)y2=cos(x)plot(x1,y1,x2,y2)legend('sin(x)','cos(x)')%坐标轴控制x=0:0.1:2*pi;y=sin(x)plot(x,y)xlim([0 10])%x坐标轴区间,注意此处格式为([])axis on%坐标轴显示,对应axis off不显示%原图保持x1=0:0.1:2*pi;x2=-pi:0.1:pi;y1=sin(x)y2=cos(x)hold on%图形保持,如不使用,y2将覆盖y1图形plot(x,y1)plot(x,y2)%窗口分隔x=0:0.1:2*pi;y1=sin(x)y2=cos(x)y3=tan(x)y4=exp(x)subplot(2,2,1)plot(x,y1)subplot(2,2,2)plot(x,y2)subplot(2,2,3)plot(x,y3)subplot(2,2,4)plot(x,y4)%多窗口显示x=0:0.1:2*pi;y1=sin(x)y2=cos(x)y3=tan(x)y4=exp(x)figure(1)%实现多窗口显示plot(x,y1)figure(2)plot(x,y2)figure(3)plot(x,y3)figure(4)plot(x,y4)。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验三 MATLAB 的绘图一、实验目的:掌握利用MATLAB 画曲线和曲面。

二、实验容:1、 在不同图形中绘制下面三个函数t ∈[0,4π]的图象,3个图形分别是figure(1),figure(2),figure(3)。

)sin(41.0321t e y ty t y t -===π说明:y 1 线型:红色实线,y 2 线型:黑色虚线,y 3: 线型:兰色点线 分别进行坐标标注,分别向图形中添加标题‘函数1’,‘函数2’, ‘函数3’ 解答:源程序与图像: t=0:0.1:4*pi; y_1=t;y_2=sqrt(t);y_3=4*pi.*exp(-0.1*t).*sin(t); figure(1)plot(t,y_1,'-r'); title('函数1');xlabel('t');ylabel('y_1'); figure(2)plot(t,y_2,'--k'); title('函数2');xlabel('t');ylabel('y_2'); figure(3)plot(t,y_3,':b'); title('函数3');xlabel('t');ylabel('y_3');函数1ty1函数2t y2函数3ty32、 在同一坐标系下绘制下面三个函数在t ∈[0,4π]的图象。

(用2种方法来画图,其中之一使用hold on ) 使用text 在图形适当的位置标注“函数1”“函数2”,“函数3” 使用gtext 重复上面的标注,注意体会gtext 和text 之间的区别 解答: 方法一: 程序与图形: t=0:0.1:4*pi; y_1=t;y_2=sqrt(t);y_3=4*pi.*exp(-0.1*t).*sin(t); figure(1)plot(t,y_1,'-r'); gtext('函数1');xlabel('t');ylabel('y'); hold onplot(t,y_2,'--k'); gtext('函数2');hold onplot(t,y_3,':b'); gtext('函数3');2468101214-10-5051015ty方法二:t=0:0.1:4*pi; y_1=t;y_2=sqrt(t);y_3=4*pi.*exp(-0.1*t).*sin(t); figure(1)plot(t,y_1,'-r',t,y_2,'--k',t,y_3,':b'); xlabel('t');ylabel('y'); text(10,10,'函数1'); text(11,2,'函数2'); text(11,-5,'函数3');02468101214-10-551015ty4、绘制ρ=sin(2θ)cos(2θ)的极坐标图源程序和图形:theta=0:pi/100:2*pi;rho=sin(2*theta).*cos(2*theta); polar(theta,rho);9027018005、绘制y=10x 2的对数坐标图并与直角线性坐标图进行比较。

在一个图形中绘制4个子图,分别使用plot 、semilogx 、semilogy 、loglog 函数进行绘制; 并且用title 进行标注;同时添加网格线 源程序与图像: x=0:0.1:5; y=10*x.^2;subplot(2,2,1) plot(x,x);title('plot 函数图');grid onsubplot(2,2,2) semilogx(x,y);title('semilogx 函数图');grid onsubplot(2,2,3) semilogy(x,y);title('semilogy');grid onsubplot(2,2,4) loglog(x,y);title('loglog 函数图');grid on0246246plot 函数图10101010100200300semilogx 函数图024610-210102104semilogy101010110-210102104loglog 函数图6、绘制下面函数在区间[-6,6]中的图象。

⎪⎩⎪⎨⎧>+-≤<≤=3,630,0,sin )(x x x x x x x y源程序和图像: x=-6:0.1:0; y_1=sin(x);plot(x,y_1,'-k');xlabel('x');ylabel('y'); gtext('y_1=sin(x)'); hold on x=0:0.1:3; y_2=x;plot(x,y_2,'--b'); gtext('y_2=x'); hold on x=3:0.1:6; y_3=-x+6;plot(x,y_3,':r'); gtext('y_3=-x+6');-6-4-20246-1-0.500.511.522.53xy7、三维空间曲线绘制t ∈[0,4π]x=cos(t); y=sin(t);使用plot3 和comet3分别绘制 源程序和图像:(彗星图用matlab 复制之后看不到,用的是截图) t=0:0.1:4*pi; x=cos(t); y=sin(t);subplot(2,1,1) plot3(t,x,y);subplot(2,1,2) comet3(t,x,y);8、分别用mesh 和surf 函数,绘制下面方程所表示的三维空间曲面,x 和y 的取值围设为[-3,3]。

101022y x z +-=源程序和图像: x=-3:0.1:3; y=-3:0.1:3;[x,y]=meshgrid(x,y);z=(-(x.^2)/10)+((y.^2)/10);subplot(2,1,1) mesh(x,y,z);title('mesh plot');xlabel('x');ylabel('y');zlabel('z');subplot(2,1,2) surf(x,y,z);title('surf plot');xlabel('x');ylabel('y');zlabel('z');xmesh plotyzxsurf plotyz9、用mesh 和surf 函数来绘制激光器输出横模的三维分布对于激光腔长为L=10, 激光波长λ=1064nm 方形镜共焦腔,其输出的几个横模如下所示意 其中πλωL os =00模的振幅分布()πλ/0022,L y x ey x v +-=10模的振幅分布()222,10osy x xey x v ω+-=01模的振幅分布()222,01osy x yey x v ω+-=20模的振幅分布()222)4(,2220osy x osexy x v ωω+--=11模的振幅分布()222,11osy x xyey x v ω+-= %激光器输出横模的三维分布 L=10e-2; %腔长Lambda=1064e-9;%波长 w_os=sqrt(L*Lambda/pi);x=[-10:0.1:10];y=[-10:0.1:10]; [x,y]=meshgrid(x,y);v_00=exp(-(x^2+y^2)/w_os^2); v_10=x*exp(-(x^2+y^2)/w_os^2); v_01=y*exp(-(x^2+y^2)/w_os^2);v_20=(4*x^2-w_os^2)*exp(-(x^2+y^2)/w_os^2); v_11=x*y*exp(-(x^2+y^2)/w_os^2);%00模 figure(1)subplot(1,2,1) mesh(x,y,v_00);title('00模mesh 图'); subplot(1,2,2) surf(x,y,v_00);title('00模surf 图');%10模 figure(2)subplot(1,2,1) mesh(x,y,v_10);title('10模mesh 图'); subplot(1,2,2) surf(x,y,v_10);title('10模surf 图');%01模 figure(3)subplot(1,2,1) mesh(x,y,v_01);title('01模mesh 图'); subplot(1,2,2) surf(x,y,v_01);title('01模surf 图');%20模 figure(4)subplot(1,2,1) mesh(x,y,v_20);title('20模mesh 图'); subplot(1,2,2) surf(x,y,v_20);title('20模surf 图');%11模 figure(5)subplot(1,2,1) mesh(x,y,v_11);title('11模mesh 图'); subplot(1,2,2) surf(x,y,v_11);title('11模surf 图');-0.010.0100模mesh 图-0.0100模surf 图-0.010.01x 10-410模mesh图-0.010.01x 10-410模surf图-8-6-4-202468-401模mesh 图0.01-401模surf 图-0.010.01x 10-620模mesh 图-0.010.01x 10-620模surf 图-0.010.01x 10-711模mesh图-0.010.01x 10-711模surf 图10、分别绘制隐函数曲线1)x 2+y 2=1 程序与图像: x=-1:0.1:1; y=-1:0.1:1;ezplot('x.^2+y.^2-1'); title('x^2+y^2=1');xyx 2+y 2=12)X 3+y 3=5xy 程序与图像: x=-10:0.1:10; y=-10:0.1:10;ezplot('x.^3+y.^3-5*x.*y'); title('x^3+y^3=5*x*y');xyx 3+y 3=5*x*y11,在光纤放大器的文献中,我们经常能碰到双Y 轴图形的绘制,在某次实验中有人得到如下的实验数据,请绘制双Y 轴图形,横坐标为输入信号功率,纵坐标分别为输出功率和增益 输入的信号光功率(mW):1;2;3;4;5;6;7;8;9;10输出的信号光功率(mW):1.1;4.2;9.2;16.1;25.3;36.0;49.4;64.5;82.0;99.9标注横坐标为Input signal power (mW),纵坐标分别为Output power (mW); Gain(dB) 解答:程序与图像:Input=[1 2 3 4 5 6 7 8 9 10];Output=[1.1 4.2 9.2 16.1 25.3 36.0 49.4 64.5 82.0 99.9]; G=Output./Input; Gain=10log10(G);[AX,H1,H2]=plotyy(Input,Output,Input,Gain);set(get(AX(1),'Ylabel'),'String','Output power (mW)') set(get(AX(2),'Ylabel'),'String','Gain(dB)') xlabel('Input signal power (mW)');20406080100O u t p u t p o w e r (m W )Input signal power (mW)G a i n (d B )12,饼图的绘制我校某级光信专业本科生源分别为:40人,3人,4人,2人,5人,请绘制饼图和进行标注为,,,,;另外在饼图中把,学生的部分分离出来, 程序和图像: x=[40 3 4 2 5]; y=[0 1 1 0 0];pie(x,y,{'40人','3人', '4人', '2人','5人'}) title('我校某级光信专业本科生源');徽3人4人江西5人我校某级光信专业本科生源。

相关文档
最新文档