中国数学建模-编程交流-【编程学习】matlab实用程序百例

合集下载

matlab数学建模程序代码

matlab数学建模程序代码

matlab数学建模程序代码【实用版】目录1.MATLAB 数学建模概述2.MATLAB 数学建模程序代码的基本结构3.常用的 MATLAB 数学建模函数和命令4.MATLAB 数学建模程序代码的编写流程5.MATLAB 数学建模程序代码的示例正文一、MATLAB 数学建模概述MATLAB(Matrix Laboratory)是一款强大的数学软件,广泛应用于数学建模、数据分析、可视化等领域。

通过 MATLAB,用户可以方便地进行数学计算、编写程序以及绘制图表等。

在数学建模领域,MATLAB 为研究人员和工程师提供了丰富的工具箱和函数,使得数学模型的构建、求解和分析变得更加简单高效。

二、MATLAB 数学建模程序代码的基本结构MATLAB 数学建模程序代码通常分为以下几个部分:1.导入 MATLAB 库:在建模过程中,可能需要使用 MATLAB 提供的某些库或工具箱,需要在代码开头进行导入。

2.定义变量和参数:在建模过程中,需要定义一些变量和参数,用于表示模型中的各个要素。

3.建立数学模型:根据实际问题,编写相应的数学表达式或方程,构建数学模型。

4.求解模型:通过调用 MATLAB 内置函数或使用自定义函数,对数学模型进行求解。

5.分析结果:对求解结果进行分析,提取所需的信息,例如计算均值、方差等统计量。

6.可视化结果:使用 MATLAB 绘制图表,将结果以直观的形式展示出来。

三、常用的 MATLAB 数学建模函数和命令MATLAB 提供了丰富的数学建模函数和命令,例如:1.线性规划:使用`linprog`函数求解线性规划问题。

2.非线性规划:使用`fmincon`或`fsolve`函数求解非线性规划问题。

3.优化问题:使用`optimize`函数求解优化问题。

4.数据处理:使用`mean`、`std`等函数对数据进行统计分析。

5.图表绘制:使用`plot`、`scatter`等函数绘制各种图表。

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轴');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轴');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')。

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','pl ot');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')欧阳语创编。

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编程案例

matlab编程案例标题:Matlab编程案例集锦1. 信号处理:使用Matlab编写一个程序,读取音频文件并对其进行频谱分析。

通过绘制频谱图,展示音频信号的频率特征,并进行简单的音频处理,如降噪、滤波等。

2. 图像处理:编写一个Matlab程序,读取一张彩色图像,并实现图像的灰度化、二值化、边缘检测、图像增强等图像处理操作。

通过比较处理前后的图像,展示算法的效果。

3. 机器学习:使用Matlab实现一个简单的线性回归模型。

根据给定的数据集,通过最小二乘法计算出最佳拟合直线,并绘制出拟合结果。

4. 数值计算:编写一个Matlab程序,实现牛顿迭代法求解非线性方程的根。

通过给定的初始值和迭代次数,计算方程的根,并展示迭代过程中的结果。

5. 数据可视化:使用Matlab绘制一个3D图像,展示一个球体的形状。

通过调整球体的半径和位置参数,观察球体形状的变化,并使用颜色映射显示球体的高度信息。

6. 控制系统:编写一个Matlab程序,设计一个PID控制器来控制一个二阶系统。

通过调整PID控制器的参数,观察系统的响应特性,并使用图表展示系统的步态响应、频率响应等。

7. 信号生成:使用Matlab生成一个复杂的信号,并对其进行时频分析。

通过绘制时频图,展示信号在时间和频率域上的变化特征,并分析信号的频谱分布。

8. 数字滤波器设计:编写一个Matlab程序,设计一个数字滤波器来对一个离散信号进行滤波。

通过选择合适的滤波器类型和参数,实现信号的去噪、平滑等效果。

9. 数字图像复原:使用Matlab对一张受到噪声污染的图像进行复原。

通过选择合适的图像复原算法,如维纳滤波、逆滤波等,实现图像的去噪和恢复。

10. 优化算法:编写一个Matlab程序,使用遗传算法来解决旅行商问题。

通过随机生成城市坐标和距离矩阵,求解旅行商的最优路径,并绘制出最优路径图。

以上是10个基于Matlab编程的案例,涵盖了信号处理、图像处理、机器学习、数值计算、数据可视化、控制系统、信号生成、数字滤波器设计、数字图像复原和优化算法等多个领域。

matlab实用程序百例3

matlab实用程序百例3
'style','pushbutton',...
'string','区域过滤一',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback',[...
'cla,',...
'k=3;,',...
'I=imread(''rice.tif'');,',...
'BW=edge(I,''canny'');,',...
'imshow(BW)']);
'I=imread(''rice.tif'');,',...
'imcontour(I)']);
b2=uicontrol('parent',h0,...
'units','points',...
'tag','b2',...
'style','pushbutton',...
u11=uimenu('parent',u1,...
'tag','u11',...
'label','SALT&PEPPER噪声',...
'backgroundcolor',[0.75 0.75 0.75],...

数学建模竞赛培训之编程MATLAB实用教程

数学建模竞赛培训之编程MATLAB实用教程
设a,b为同维向量,则c=a+b 或c=a-b得到两个向量 相加减的结果。
向量与常数的相加减为每个元素加减这个常数。
例如:
b=a+2
得到
b= 3 4 5 6 7 8 11 10 9 c=a+b
c= 4 6 8 10 12 14 20 18 16
8
(3)向量的乘除运算
a. 向量的乘法运算
点积运算的运算符为 .*, 其意义为两个向量的对 应元素进行乘法运算,例如
数,此时,多项式系数以降幂形式排列。 p = poly(E) p=
1.0000 -5.0000 -2.0000
16
其他特殊矩阵的生成方法: 1)、eye (m,n)或eye (m) 产生m*n 或 m*m的单位
矩阵。例如: eye (3,4)与eye (3)分别产生如下矩阵:
1000
100
0100
[ cos(l)*sin(f), -r*sin(l)*sin(f), r*cos(l)*cos(f)]
[ sin(l),
r*cos(l),
0
]
28
2.积分:用函数int来求符号表达式的积分。命令格 式为: int (f, r, x0, x1)其中f为所要积分的表达式,r 为积分变量,若为定积分,则x0,x1为积分上下 限。例: sym x; sym k real f=exp(-(k*x)^2) f= exp(-k^2*x^2) int(f,x,-inf,inf) ans = signum(k)/k*pi^(1/2)
27
3)、可用函数jacobian来计算Jacobi矩阵。 syms r l f x=r*cos(l)*cos(f); y=r*cos(l)*sin(f); z=r*sin(l); J=jacobian([x;y;z],[r l f])

matlab实用程序实例

matlab实用程序实例

实例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])。

MATLAB数学实验100例题解

MATLAB数学实验100例题解

一元函数微分学实验1 一元函数的图形(基础实验)实验目的 通过图形加深对函数及其性质的认识与理解, 掌握运用函数的图形来观察和分析 函数的有关特性与变化趋势的方法,建立数形结合的思想; 掌握用Matlab 作平面曲线图性的方法与技巧。

初等函数的图形2 作出函数x y tan =和x y cot =的图形观察其周期性和变化趋势。

解:程序代码:>〉 x=linspace (0,2*pi,600); t=sin (x)。

/(cos (x )+eps );plot(x ,t);title (’tan (x )');axis ([0,2*pi ,-50,50]); 图象:程序代码: 〉〉 x=linspace (0,2*pi,100); ct=cos (x)。

/(sin(x)+eps ); plot(x,ct );title(’cot(x)');axis ([0,2*pi ,—50,50]); 图象:cot(x)4在区间]1,1[-画出函数xy 1sin =的图形。

解:程序代码:>> x=linspace (-1,1,10000);y=sin(1。

/x ); plot (x,y ); axis ([-1,1,—2,2]) 图象:二维参数方程作图6画出参数方程⎩⎨⎧==t t t y tt t x 3cos sin )(5cos cos )(的图形:解:程序代码:>〉 t=linspace(0,2*pi,100); plot(cos(t ).*cos (5*t ),sin(t )。

*cos(3*t)); 图象:极坐标方程作图8 作出极坐标方程为10/t e r =的对数螺线的图形. 解:程序代码:〉〉 t=0:0.01:2*pi ; r=exp (t/10);polar(log(t+eps ),log (r+eps)); 图象:90270分段函数作图10 作出符号函数x y sgn =的图形。

matlab实用程序百例(6)

matlab实用程序百例(6)

matlab实用程序百例(6)可设置函数曲线光源的用户界面h0=figure('toolbar','none',...'position',[198****8468],...'name','实例53');h1=axes('parent',h0,...'position',[0.15 0.5 0.7 0.5],...'visible','off');[x,y]=meshgrid(-8:0.5:8);r=sqrt(x.^2+y.^2)+eps;z=sin(r)./r;fh=surf(x,y,z);shading interpview([-60 30])camlight leftlightk=light('position',[0 -2 1]);button1=uicontrol('parent',h0,...'style','pushbutton',...'string','设置光线',...'position',[80 60 70 30],...'callback',[...'an1=inputdlg(''光线来源的X轴坐标'');,',... 'k1=str2num(an1{1});,',...'an2=inputdlg(''光线来源的Y轴坐标'');,',... 'k2=str2num(an2{1});,',...'an3=inputdlg(''光线来源的Z轴坐标'');,',... 'k3=str2num(an3{1});,',...'set(lightk,''position'',[k1 k2 k3]);,',...'set(edit1,''string'',[''['',num2str(k1),'''',num2str(k2),'' '',num2str(k3),'']'']);']);button2=uicontrol('parent',h0,...'style','pushbutton',...'string','关闭',...'position',[250 60 70 30],...'callback','close');edit1=uicontrol('parent',h0,...'style','edit',...'max',2,...'min',0,...'fontsize',15,...'backgroundcolor',[1 1 1],...'string','[0 -2 1]',...'position',[80 110 220 30]);text1=uicontrol('parent',h0,...'style','text',...'backgroundcolor',[0.75 0.75 0.75],...'fontsize',15,...'string','光线来源坐标',...'position',[80 140 220 30]);添加效果h0=figure('toolbar','none',...'position',[200 50 300 350],...'name','实例54');h1=axes('parent',h0,...'position',[0.2 0.4 0.6 0.6],...'visible','off');ezsurf('sin(sqrt(x.^2+y.^2))/sqrt(x.^2+y.^2)',[-6*pi,6*pi]) b1=uicontrol('parent',h0,...'units','points',...'tag','b1',...'style','pushbutton',...'string','设置',...'backgroundcolor',[0.75 0.75 0.75],... 'position',[40 50 50 20],...'callback',[...'view(0,75);,',...'shading interp;,',...'lightangle(-45,30);,',...'k=findobj(gca,''type'',''surface'');,'... 'set(k,''facelighting'',''phong'');,',... 'set(k,''ambientstrength'',0.3);,',...'set(k,''diffusestrength'',0.8);,',...'set(k,''specularstrength'',0.9);,',...'set(k,''specularexponent'',25);,',... 'set(k,''backfacelighting'',''unlit'')']); b2=uicontrol('parent',h0,...'units','points',...'tag','b2',...'style','pushbutton',...'string','关闭',...'backgroundcolor',[0.75 0.75 0.75],... 'position',[120 50 50 20],...'callback','close');查询日期h0=figure('toolbar','none',...'position',[198****8468],...'name','实例55');h1=axes('parent',h0,...'position',[0.15 0.5 0.7 0.5],...'visible','off');huidiao=[...'yearnum=str2num(get(edit1,''string''));,',...'monthnum=str2num(get(edit2,''string''));,',...'daynum=str2num(get(edit3,''string''));,',...'monthday=[0 31 28 31 30 31 30 31 31 30 31 30 31];,',... 'dyear=yearnum-2000;,',...'beishu=fix(dyear/4);,',...'yushu=rem(yearnum,4);,',...'if yushu==0,',...'monthday(3)=29;,',...'end,',...'mday=0;,',...'for i=1:monthnum,',...'mday=monthday(i)+mday;,',...'end,',...'yearday=mday+daynum-1;,',...'noweek=fix(yearday/7);,',...'set(edit5,''string'',[''第'',num2str(noweek),''周'']);,',...'if dyear>0,',...'if yushu==0,',...'beishu=beishu-1;,',...'end,',...'dday=yearday+365*dyear+beishu+1;,',...'end,',...'if dyear<=0,',...'dday=365*dyear+yearday+beishu;,',...'end,',...'mweek=rem(dday,7)+7;,',...'set(edit4,''string'',''Sunday'');,',...'end,',...'if mweek==9,',...'set(edit4,''string'',''Monday'');,',...'end,',...'if mweek==10,',...'set(edit4,''string'',''Tuesday'');,',...'end,',...'if mweek==11,',...'set(edit4,''string'',''Wednesday'');,',... 'end,',...'if mweek==12,',...'set(edit4,''string'',''Thursday'');,',... 'end,',...'if mweek==13,',...'set(edit4,''string'',''Friday'');,',...'end,',...'if mweek==7,',...'set(edit4,''string'',''Saturday'');,',... 'end,',...'if mweek==6,',...'set(edit4,''string'',''Friday'');,',...'end,',...'if mweek==5,',...'set(edit4,''string'',''Thursday'');,',... 'end,',...'if mweek==4,',...'set(edit4,''string'',''Wednesday'');,',... 'end,',...'set(edit4,''string'',''Tuesday'');,',... 'end,',...'if mweek==2,',...'set(edit4,''string'',''Monday'');,',... 'end,',...'if mweek==1,',...'set(edit4,''string'',''Sunday'');,',... 'end'];edit1=uicontrol('parent',h0,...'style','edit',...'horizontalalignment','right',...'position',[40 300 50 20]);text1=uicontrol('parent',h0,...'style','text',...'string','年',...'horizontalalignment','left',...'position',[90 300 50 20]);edit2=uicontrol('parent',h0,...'style','edit',...'horizontalalignment','right',...'position',[160 300 50 20]);text2=uicontrol('parent',h0,...'style','text',...'string','月',...'horizontalalignment','left',...'position',[210 300 50 20]);edit3=uicontrol('parent',h0,...'style','edit',...'horizontalalignment','right',...'position',[280 300 50 20]);text3=uicontrol('parent',h0,... 'style','text',...'string','日',...'horizontalalignment','left',...'position',[330 300 50 20]);edit4=uicontrol('parent',h0,... 'style','edit',...'horizontalalignment','left',...'position',[210 200 120 20]); text4=uicontrol('parent',h0,... 'style','text',...'string','查找的日期为',...'horizontalalignment','right',... 'position',[110 200 100 20]); edit5=uicontrol('parent',h0,... 'style','edit',...'horizontalalignment','left',...'position',[210 100 120 20]); text1=uicontrol('parent',h0,... 'style','text',...'string','该日处于',...'horizontalalignment','left',...'position',[160 100 50 20]); button1=uicontrol('parent',h0,... 'style','pushbutton',...'position',[80 40 80 30],...'string','开始',...'callback',huidiao);button2=uicontrol('parent',h0,...'style','pushbutton',...'position',[220 40 80 30],...'string','关闭',...'callback','close');图形效果(1)h0=figure('toolbar','none',...'position',[198****0468],...'name','实例56');h1=axes('parent',h0,...'position',[0.3 0.45 0.5 0.5],...'visible','off');l1=uimenu(gcf,'label','Draw figure',... 'tag','l1');huidiao=[...'if get(r1,''value'')==1,',...'shading faceted,',...'end,',...'if get(r2,''value'')==1,',...'shading flat,',...'end,',...'if get(r3,''value'')==1,',...'shading interp,',...'end,',...'k=get(p1,''value'');,',...'switch k,',...'case 1,',...'colormap(''cool''),',...'case 2,',...'colormap(''spring''),',...'case 3,',...'colormap(''summer''),',...'case 4,',...'colormap(''autumn''),',...'case 5,',...'colormap(''winter''),',...'end'];l11=uimenu('parent',l1,...'label','Surface',...'tag','l11',...'callback',[...'[x,y]=meshgrid(-8:0.5:8);,',... 'r=sqrt(x.^2+y.^2)+eps;,',... 'z=sin(r)./r;,',...'surf(x,y,z),',... huidiao]);l12=uimenu('parent',l1,...'label','Mesh',...'tag','l12',...'callback',[...'mesh(peaks),',... huidiao]);l13=uimenu('parent',l1,...'label','Membrane',...'tag','l13',...'callback',[...'mesh(membrane),',... huidiao]);f1=uicontrol('parent',h0,... 'units','points',...'listboxtop',0,...'position',[12 6 100 101],...'style','frame',...'tag','f1');r1=uicontrol('parent',h0,...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'position',[19.5 58.5 72.75 16.5],...'string','shading faceted',...'style','radiobutton',...'tag','r1',...'value',1,...'callback',[...'shading faceted,',...'set(r1,''value'',1);,',...'set(r2,''value'',0);,',...'set(r3,''value'',0);']);r2=uicontrol('parent',h0,...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'position',[19.5 35.25 78.75 18.75],...'string','shading flat',...'style','radiobutton',...'tag','r2',...'value',0,...'callback',[...'shading flat,',...'set(r2,''value'',1);,',...'set(r1,''value'',0);,',...'set(r3,''value'',0);']);r3=uicontrol('parent',h0,...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'position',[19.5 12.75 71.25 18.75],...'string','shading interp',...'style','radiobutton',...'tag','r3',...'value',0,...'callback',[...'shading interp,',...'set(r3,''value'',1);,',...'set(r1,''value'',0);,',...'set(r2,''value'',0);']);t1=uicontrol('parent',h0,...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'fontsize',12,...'listboxtop',0,...'position',[14.25 75.75 90.75 22.5],...'string','平滑处理',...'style','text',...'tag','t1');t2=uicontrol('parent',h0,...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'fontsize',12,...'listboxtop',0,...'position',[117 69 72.75 17.5],...'string','设置色调',...'style','text',...'tag','t2');p1=uicontrol('parent',h0,...'units','points',...'backgroundcolor',[0.753 0.753 0.753],...'listboxtop',0,...'position',[116.25 39 72.75 20.25],...'string','Cool|Spring|Summer|Autumn|Winter',... 'style','popupmenu',...'tag','p1',...'value',1,...'callback',[...'k=get(p1,''value'');,',...'switch k,',...'case 1,',...'colormap(''cool''),',...'case 2,',...'colormap(''spring''),',...'case 3,',...'colormap(''summer''),',...'case 4,',...'colormap(''autumn''),',...'case 5,',...'colormap(''winter''),',...'end']);b1=uicontrol('parent',h0,...'units','points',...'backgroundcolor',[0.753 0.753 0.753],...'listboxtop',0,...'position',[12 243 72.75 30.75],...'string','关闭',...'tag','b1',...'callback','close');b2=uicontrol('parent',h0,...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'position',[216.75 67.5 83.25 18.75],... 'string','Colorbar',...'tag','b2',...'callback','colorbar');图形效果h0=figure('toolbar','none',...'position',[168 94.5 315 289.5],...'name','实例57');h1=axes('parent',h0,...'position',[0.4 0.4 0.5 0.5],...'visible','off');f1=uicontrol('parent',h0,...'style','frame',...'position',[15 10 80 70],...'string','dull',...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'tag','r1',...'value',1,...'callback',[...'set(r1,''value'',1);,',...'set(r2,''value'',0);,',...'set(r3,''value'',0);,',...'material dull']);r1=uicontrol('parent',h0,...'style','radiobutton',...'position',[19.5 58.5 72.75 16.5],...'string','dull',...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'tag','r1',...'value',1,...'callback',[...'set(r1,''value'',1);,',...'set(r2,''value'',0);,',...'set(r3,''value'',0);,',...'material dull']);r2=uicontrol('parent',h0,...'style','radiobutton',...'position',[19.5 35.25 72.75 16.5],...'string','metal',...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'tag','r2',...'value',0,...'callback',[...'set(r2,''value'',1);,',...'set(r1,''value'',0);,',...'set(r3,''value'',0);,',...'material metal']);r3=uicontrol('parent',h0,...'style','radiobutton',...'position',[19.5 12.75 72.75 16.5],...'string','shiny',...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'tag','r3',...'value',0,...'callback',[...'set(r3,''value'',1);,',...'set(r1,''value'',0);,',...'set(r2,''value'',0);,',...'material shiny']);u1=uimenu('parent',h0,...'label','绘图',...'backgroundcolor',[0.753 0.753 0.753],... 'tag','u1',...'callback',[...'[x,y]=meshgrid(-8:0.5:8);,',...'r=sqrt(x.^2+y.^2)+eps;,',...'z=sin(r)./r;,',...'surf(x,y,z),',...'shading interp']);b1=uicontrol('parent',h0,...'style','pushbutton',...'position',[19.5 150 60 20],...'string','light',...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'tag','b1',...'callback','camlight headlight');b2=uicontrol('parent',h0,...'style','pushbutton',...'position',[19.5 100 60 20],...'string','关闭',...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'tag','b2',...'callback','close');可控制小球运动速度的用户界面h0=figure('toolbar','none',...'position',[198****0468],...'name','实例58');h1=axes('parent',h0,...'position',[0.25 0.45 0.5 0.5],...'visible','off');t=0:0.1:4*pi;x=sin(t);y=cos(t);plot(x,y)axis equalaxis offh=line('color',[1 0 0],...'linestyle','.',...'xdata',0,...'ydata',1,...'markersize',20,...'erasemode','xor');n=length(t);i=1;speed=0.01;k=0;b1huidiao=[...'k=0;,',...'while 1,',...'set(h,''xdata'',x(i),''ydata'',y(i));,',... 'drawnow,',...'pause(speed),',...'i=i+1;,',...'if i>n,',...'i=1;,',...'end,',...'if k==1,',...'break,',...'end,',...'end'];b1=uicontrol('parent',h0,...'units','points',...'tag','b1',...'style','pushbutton',...'string','开始',...'backgroundcolor',[0.75 0.75 0.75],... 'position',[30 80 50 20],...'callback',b1huidiao);b2=uicontrol('parent',h0,...'units','points',...'style','pushbutton',...'string','停止',...'backgroundcolor',[0.75 0.75 0.75],... 'position',[100 80 50 20],...'callback','k=1;');b3=uicontrol('parent',h0,...'units','points',...'tag','b3',...'style','pushbutton',...'string','关闭',...'backgroundcolor',[0.75 0.75 0.75],... 'position',[170 80 50 20],...'callback',[...'k=1;,',...'close']);s1=uicontrol('parent',h0,...'units','points',...'tag','s1',...'style','slider',...'value',50*speed,...'max',1,...'min',0,...'backgroundcolor',[0.75 0.75 0.75],... 'position',[30 115 190 20],...'callback',[...'m=get(s1,''value'');,',...'speed=m/50;']);t1=uicontrol('parent',h0,...'units','points',...'style','text',...'fontsize',15,...'string','小球运动速度',...'backgroundcolor',[0.75 0.75 0.75],...'position',[30 135 190 20]);设置坐标轴纵横轴比h0=figure('name','实例59');h1=axes('parent',h0,...'position',[0.3 0.45 0.5 0.5],...'visible','off');u1=uimenu('parent',h0,...'label','绘图',...'backgroundcolor',[0.753 0.753 0.753],... 'tag','u1',...'callback',[...'[x,y]=meshgrid(-8:0.5:8);,',...'r=sqrt(x.^2+y.^2)+eps;,',...'z=sin(r)./r;,',...'mesh(x,y,z),',...'shading interp,',...'axis normal']);f1=uicontrol('parent',h0,...'units','points',...'listboxtop',0,...'position',[12 6 100 150],...'style','frame',...'tag','f1');t1=uicontrol('parent',h0,...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'position',[19.5 130 72.75 16.5],...'string','坐标纵横比',...'style','text',...'tag','t1');r1=uicontrol('parent',h0,...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'position',[19.5 110 72.75 16.5],...'string','axis equal',...'style','radiobutton',...'tag','r1',...'value',1,...'callback',[...'set(r1,''value'',1);,',...'set(r2,''value'',0);,',...'set(r3,''value'',0);,',...'set(r4,''value'',0);,',...'set(r5,''value'',0);,',...'axis equal']);r2=uicontrol('parent',h0,...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'position',[19.5 85 72.75 16.5],...'string','axis square',...'style','radiobutton',...'tag','r2',...'value',0,...'callback',[...'set(r2,''value'',1);,',...'set(r1,''value'',0);,',...'set(r3,''value'',0);,',...'set(r4,''value'',0);,',...'set(r5,''value'',0);,',...'axis square']);r3=uicontrol('parent',h0,...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'position',[19.5 60 72.75 16.5],...'string','axis image',...'style','radiobutton',...'tag','r3',...'value',0,...'callback',[...'set(r3,''value'',1);,',...'set(r2,''value'',0);,',...'set(r1,''value'',0);,',...'set(r4,''value'',0);,',...'set(r5,''value'',0);,',...'axis image']);r4=uicontrol('parent',h0,...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'position',[19.5 35 72.75 16.5],...'string','axie vis3d',...'style','radiobutton',...'tag','r4',...'value',0,...'callback',[...'set(r4,''value'',1);,',...'set(r2,''value'',0);,',...'set(r3,''value'',0);,',...'set(r1,''value'',0);,',...'set(r5,''value'',0);,',...'axis vis3d']);r5=uicontrol('parent',h0,...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'position',[19.5 10 72.75 16.5],...'string','axis auto',...'style','radiobutton',...'tag','r5',...'value',0,...'callback',[...'set(r5,''value'',1);,',...'set(r2,''value'',0);,',...'set(r3,''value'',0);,',...'set(r4,''value'',0);,',...'set(r1,''value'',0);,',...'axis auto']);b1=uicontrol('parent',h0,...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'position',[12 243 72.75 30.75],...'string','关闭',...'tag','b1',...'callback','close');b2=uicontrol('parent',h0,...'units','points',...'backgroundcolor',[0.753 0.753 0.753],... 'listboxtop',0,...'position',[216.75 67.5 83.25 18.75],... 'string','Colorbar',...'tag','b2',...'callback','colorbar');动态文本显示h0=figure('toolbar','none',...'position',[198****0468],...'name','实例60');h1=axes('parent',h0,...'position',[0.25 0.45 0.5 0.5],...'visible','off');str1='当前阻尼比=';z=0.52;t=0:0.1:10;y=step(1,[1 2*z 1],t);hline=plot(t,y);grid onr1=uicontrol('parent',h0,...'units','points',...'tag','r1',...'style','radio',...'string','grid on',...'position',[30 120 60 20],...'backgroundcolor',[0.75 0.75 0.75],... 'value',1,...'callback',[...'grid on,',...'set(r1,''value'',1);,',...'set(r2,''value'',0)']);r2=uicontrol('parent',h0,...'units','points',...'tag','r2',...'style','radio',...'string','grid on',...'position',[30 95 60 20],...'backgroundcolor',[0.75 0.75 0.75],... 'value',0,...'callback',[...'grid off,',...'set(r2,''value'',1);,',...'set(r1,''value'',0)']);s1=uicontrol('parent',h0,...'units','points',...'tag','s1',...'style','slider',...'value',z,...'position',[100 95 150 20],...'backgroundcolor',[0.75 0.75 0.75],... 'max',1,...'min',0,...'callback',[...'z=get(s1,''value'');,',...。

数学建模中30道经典MATLAB程序

数学建模中30道经典MATLAB程序

编程1、编写一程序,要求输入五个整数,然后由小到大排序再输出。

%输入n个数,然后由小到大输出a=input('输入数据:')n=length(a); %输入数据的长度i=1;j=1; %赋初值for i=1:n %需要进行n次比较for j=2:n %与相邻的进行n-1次比较if a(j-1)>a(j)b=a(j-1);a(j-1)=a(j);a(j)=b; %比较前者是否比后者大,大的就互换endendendfprintf(' %d',a) ;2、将一个整型数组的元素按逆序重新存放(如原序为:8,6,5,4改为4,5,6,8)。

function lin5a=input('输入数据:')n=length(a);%求输入a的长度for i=1:n/2b=a(i);a(i)=a(n+1-i);a(n+1-i)=b;endfprintf(' %d',a)3、输入一个字符,如果是大写字母,则将其转换成小写并输出,若是小写,则直接输出;若是非字母字符则打印:‘datarror’.function xin2a=input('输入数据:','s')if a>=65&a<=90fprintf('shuchu is %c\n',a+32);elseif a>=97&a<=122fprintf('shuchu is %c\n',a);elsea='dataerror';fprintf('shuchu is %s',a);end4、输入一个整数,写一程序输出它是几位数。

function lin6a=input('输入数据:','s')n=length(a)%求输入a的长度b=n;fprintf('weishu %d',b);end5、写一程序求1!+2!+ (10)function wi=1;j=1;s=0; %赋初值while i<=10j=j*i;s=s+j;i=i+1;endfprintf('s is %d\n',s);6、从键盘上输入a与n的值,计算sum=a+aa+aaa+aaaa+……(共n项)的和。

matlab仿真实例100题

matlab仿真实例100题

matlab仿真实例100题Matlab是一种强大的数学软件,广泛应用于科学计算、数据分析和工程仿真等领域。

在学习和使用Matlab的过程中,通过实例的方式进行仿真练习是一种非常有效的学习方法。

下面将给出100个Matlab仿真实例题目,帮助读者更好地掌握Matlab的使用。

1. 编写一个程序,计算并输出1到100之间所有奇数的和。

2. 编写一个程序,计算并输出1到100之间所有偶数的乘积。

3. 编写一个程序,计算并输出1到100之间所有素数的个数。

4. 编写一个程序,计算并输出1到100之间所有整数的平方和。

5. 编写一个程序,计算并输出1到100之间所有整数的立方和。

6. 编写一个程序,计算并输出1到100之间所有整数的阶乘和。

7. 编写一个程序,计算并输出1到100之间所有整数的倒数和。

8. 编写一个程序,计算并输出1到100之间所有整数的平均值。

9. 编写一个程序,计算并输出1到100之间所有整数的中位数。

10. 编写一个程序,计算并输出1到100之间所有整数的标准差。

11. 编写一个程序,计算并输出1到100之间所有整数的方差。

12. 编写一个程序,计算并输出1到100之间所有整数的最大值。

13. 编写一个程序,计算并输出1到100之间所有整数的最小值。

15. 编写一个程序,计算并输出1到100之间所有整数的平方根和。

16. 编写一个程序,计算并输出1到100之间所有整数的立方根和。

17. 编写一个程序,计算并输出1到100之间所有整数的对数和。

18. 编写一个程序,计算并输出1到100之间所有整数的指数和。

19. 编写一个程序,计算并输出1到100之间所有整数的正弦和。

20. 编写一个程序,计算并输出1到100之间所有整数的余弦和。

21. 编写一个程序,计算并输出1到100之间所有整数的正切和。

22. 编写一个程序,计算并输出1到100之间所有整数的双曲正弦和。

23. 编写一个程序,计算并输出1到100之间所有整数的双曲余弦和。

matlab数学建模程序代码

matlab数学建模程序代码

matlab数学建模程序代码摘要:1.MATLAB 简介2.MATLAB 数学建模应用领域3.MATLAB 数学建模程序代码实例4.总结正文:一、MATLAB 简介MATLAB(Matrix Laboratory)是一款广泛应用于科学计算、数据分析和可视化的软件,尤其擅长矩阵运算。

自1984 年问世以来,MATLAB 已经成为了全球数百万工程师、科学家和研究人员的得力工具。

MATLAB 具有丰富的函数库和强大的编程能力,为用户提供了从数据获取、数据处理、数据分析到结果可视化等一站式解决方案。

二、MATLAB 数学建模应用领域MATLAB 在数学建模领域的应用非常广泛,涵盖了诸如优化、控制、信号处理、图像处理、概率论和统计等众多学科。

以下是一些典型的应用场景:1.优化问题求解:线性规划、整数规划、非线性规划等。

2.控制系统设计:线性时不变系统、线性时变系统、非线性系统等。

3.信号处理:滤波、信号生成、频域分析等。

4.图像处理:图像增强、图像分割、特征提取等。

5.概率论与统计:概率分布计算、假设检验、回归分析等。

三、MATLAB 数学建模程序代码实例下面以一个简单的线性规划问题为例,展示如何使用MATLAB 进行数学建模。

问题描述:给定如下线性规划问题:```maximize: c" * xsubject to: A * x <= b and x >= 0```其中,c"表示目标函数的系数向量,A 表示不等式约束矩阵,b 表示不等式约束向量,x 表示决策变量向量。

MATLAB 代码如下:```matlab% 定义参数c = [1, 2, 3]; % 目标函数系数向量A = [1, 0; 0, 2; 0, 1]; % 不等式约束矩阵b = [2; 4; 1]; % 不等式约束向量x = linprog(c, [], [], A, b); % 求解线性规划问题disp(x); % 输出最优解```运行上述代码,可以得到最优解x = [1.5; 2.5; 1]。

matlab实用程序百例(3)设...

matlab实用程序百例(3)设...

matlab实用程序百例(3)设...matlab实用程序百例实例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****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('弹出式菜单的使用')hold on。

matlab实用程序百例2

matlab实用程序百例2
t3=uicontrol('parent',h0,...
'style','text',...
'string','Y轴最小值',...
'position',[270 145 80 20]);
e4=uicontrol('parent',h0,...
'style','edit',...
'style','pushbutton',...
'string',':',...
'fontsize',20,...
'foregroundcolor',[1 1 1],...
'backgroundcolor',[0 0 0],...
'position',[170 100 50 20],...
'string','o',...
'fontsize',20,...
'foregroundcolor',[1 1 1],...
'backgroundcolor',[0 0 0],...
'position',[170 100 50 20],...
'callback','set(k,''marker'',''o'')');
'backgroundcolor',[0 0 0],...

数学建模竞赛培训之编程MATLAB实用教程

数学建模竞赛培训之编程MATLAB实用教程

数学建模竞赛培训之编程MATLAB实用教程在当今的学术和工程领域,数学建模竞赛越来越受到重视,而MATLAB 作为一款强大的数学计算和编程软件,在其中发挥着至关重要的作用。

如果你正在为数学建模竞赛做准备,那么掌握 MATLAB 的编程技巧将为你在竞赛中取得优异成绩提供有力的支持。

接下来,让我们一起开启 MATLAB 编程的实用教程之旅。

一、MATLAB 基础首先,我们来了解一下 MATLAB 的基本操作界面。

当你打开MATLAB 时,会看到一个命令窗口,这是我们输入命令和查看结果的地方。

变量是编程中的重要概念,在 MATLAB 中,变量无需事先声明类型,直接赋值即可使用。

例如,我们可以输入`x = 5` ,此时`x` 就被赋值为 5 。

MATLAB 支持多种数据类型,如数值型(包括整数和浮点数)、字符型、逻辑型等。

二、矩阵操作矩阵在数学建模中经常用到,MATLAB 对矩阵的操作非常方便。

可以通过直接输入元素来创建矩阵,比如`A = 1 2 3; 4 5 6` 就创建了一个 2 行 3 列的矩阵`A` 。

矩阵的运算也十分简单,加法、减法、乘法等都有相应的运算符。

例如,两个矩阵相加可以直接使用`A + B` 。

三、函数的使用MATLAB 拥有丰富的内置函数,大大提高了编程效率。

比如求矩阵的行列式可以使用`det()`函数,求矩阵的逆可以使用`inv()`函数。

我们还可以自己定义函数,语法如下:```matlabfunction output_args = function_name(input_args)%函数体end```四、绘图功能在分析数据和展示结果时,绘图是必不可少的。

MATLAB 能够绘制各种类型的图形,如折线图、柱状图、饼图等。

以绘制简单的折线图为例,使用`plot()`函数,如`plot(x,y)`,其中`x` 和`y` 是数据向量。

五、数值计算在数学建模中,常常需要进行数值计算,如求解方程、求积分等。

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轴');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')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')。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
为了大学生数学建模,我愿和你成为朋友吧!
一起努力,分享好东西!分享快乐!!
2004-5-31 21:18:43
宝宝
头衔:不可不信缘
【编程学习】matlab实用程序百例
实例1:三角函数曲线(1)
function shili01
h0=figure('toolbar','none',...
'position',[198 56 350 300],...
axis([0 2*pi -1 1])
----------------------------------------------
为了大学生数学建模,我愿和你成为朋友吧!
一起努力,分享好东西!分享快乐!!
t=0:pi/10:2*pi;
[x,y]=meshgrid(t);
subplot(2,2,1)
plot(sin(t),cos(t))
axis equal
为了大学生数学建模,我愿和你成为朋友吧!
一起努力,分享好东西!分享快乐!!
2004-5-31 21:17:00
宝宝
头衔:不可不信缘
grid on
xlabel('自变量X');
ylabel('函数值Y');
title('三角函数');
----------------------------------------------
subplot(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);
function shili03
h0=figure('toolbar','none',...
'position',[200 150 450 350],...
'name','实例03');
中国数学建模 → 学术区 → 编程交流 → 【编程学习】matlab实用程序百例
您是本帖的第 2182 个阅读者
* 贴子主题:【编程学习】matlab实用程序百例
宝宝
宝宝
头衔:不可不信缘
等级:贵宾
威望:3
文章:1116
积分:3459
门派:宝宝堂
注册:2003-7-8
中国数学建模-编程交流-【编程学习】matlab实用程序百例
wh-ee 重登录 隐身 用户控制面板 搜索 风格 论坛状态 论坛展区 社区服务 社区休闲 网站首页 退出
>> VC++,C,Perl,Asp...编程学习,算法介绍. 我的收件箱 (0)
x=-pi:0.05:pi;
y1=sin(x);
y2=cos(x);
plot(x,y1,...
'-*r',...
x,y2,...
头衔:不可不信缘
等级:贵宾
威望:3
文章:1116
积分:3459
门派:宝宝堂
注册:2003-7-8
鲜花(1) 鸡蛋(0) 楼主
2004-5-31 21:23:51
宝宝
头衔:不可不信缘
等级:贵宾
威望:3
文章:1116
积分:3
function shili02
h0=figure('toolbar','none',...
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');
'position',[200 150 450 350],...
'name','实例02');
x=-pi:0.05:pi;
y=sin(x)+cos(x);
plot(x,y,'-*r','linewidth',1);
'--og');
grid on
xlabel('自变量X');
ylabel('函数值Y');
title('三角函数');
----------------------------------------------
function shili04
h0=figure('toolbar','none',...
'position',[200 150 450 250],...
'name','实例04');
门派:宝宝堂
注册:2003-7-8
第 6 楼
实例6:图形标注
function shili06
为了大学生数学建模,我愿和你成为朋友吧!
一起努力,分享好东西!分享快乐!!
2004-5-31 21:20:07
宝宝
头衔:不可不信缘
----------------------------------------------
为了大学生数学建模,我愿和你成为朋友吧!
一起努力,分享好东西!分享快乐!!
2004-5-31 21:16:02
等级:贵宾
威望:3
文章:1116
积分:3459
门派:宝宝堂
注册:2003-7-8
第 5 楼
实例5:单个轴窗口显示多个图形
function shili05
h0=figure('toolbar','none',...
'position',[200 150 450 250],...
'name','实例05');
axes(haxes(1))
ylabel('semilog plot');
axes(haxes(2))
ylabel('linear plot');
----------------------------------------------
plot(t,h)
axis([0 2*pi -2 2])
subplot(2,2,4)
g=(sin(x).^2)-(cos(y).^2);
plot(t,g)
等级:贵宾
威望:3
文章:1116
积分:3459
门派:宝宝堂
注册:2003-7-8
第 3 楼
实例3:图形的叠加
plot(x,y);
xlabel('自变量X');
ylabel('函数值Y');
title('SIN( )函数曲线');
grid on
[此贴子已经被作者于2004-6-1 17:38:17编辑过]
'name','实例01');
h1=axes('parent',h0,...
'visible','off');
x=-pi:0.05:pi;
y=sin(x);
等级:贵宾
威望:3
文章:1116
积分:3459
门派:宝宝堂
注册:2003-7-8
第 4 楼
实例4:双y轴图形的绘制
相关文档
最新文档