好文档 - 专业文书写作范文服务资料分享网站

Matlab100个实例程序

天下 分享 时间: 加入收藏 我要投稿 点赞

y=sin(x); plot(x,y); xlabel('x'); ylabel('y');

title('坐标轴范围的改变'); h=get(gca,'xlim'); k=get(gca,'ylim');

e1=uicontrol('parent',h0,... 'style','edit',...

'string',eval(num2str(h(1))),... 'horizontalalignment','right',... 'position',[80 120 100 20]); t1=uicontrol('parent',h0,... 'style','text',... 'string','x轴最小值',... 'position',[100 145 80 20]); e2=uicontrol('parent',h0,... 'style','edit',...

'string',eval(num2str(h(2))),... 'horizontalalignment','right',... 'position',[80 60 100 20]); t2=uicontrol('parent',h0,... 'style','text',... 'string','x轴最大值',... 'position',[100 85 80 20]); e3=uicontrol('parent',h0,... 'style','edit',...

'string',eval(num2str(k(1))),... 'horizontalalignment','right',... 'position',[250 120 100 20]); t3=uicontrol('parent',h0,... 'style','text',... 'string','y轴最小值',... 'position',[270 145 80 20]); e4=uicontrol('parent',h0,... 'style','edit',...

'string',eval(num2str(k(2))),...

'horizontalalignment','right',... 'position',[250 60 100 20]); t4=uicontrol('parent',h0,... 'style','text',... 'string','x轴最小值',... 'position',[270 85 80 20]); p1=uicontrol('parent',h0,... 'style','pushbutton',... 'string','设置',...

'position',[105 10 50 30],... 'callback',[...

'a=str2num(get(e1,''string''));,',... 'b=str2num(get(e2,''string''));,',... 'c=str2num(get(e3,''string''));,',... 'd=str2num(get(e4,''string''));,',... 'axis([a b c d]),',... 'drawnow']);

p2=uicontrol('parent',h0,... 'style','pushbutton',... 'string','关闭',...

'position',[275 10 50 30],... 'callback','close');

实例50:绘制不同函数曲线的用户界面 h0=figure('toolbar','none',... 'position',[198 56 408 468],... 'name','实例50'); h1=axes('parent',h0,...

'position',[0.29 0.45 0.7 0.5],... 'visible','on');

f=uicontrol('parent',h0,... 'style','frame',...

'position',[5 50 90 400]); p1=uicontrol('parent',h0,... 'style','pushbutton',... 'position',[150 100 60 40],... 'string','绘图',...

'callback',[...

'm=str2num(get(e1,''string''));,',... 'n=str2num(get(e2,''string''));,',... 'a=get(l1,''value'');,',... 'x=m:0.1:n;',... 'if a==1,',... 'plot(x,sin(x)),',... 'end,',... 'if a==2,',... 'plot(x,cos(x)),',... 'end,',... 'if a==3,',... 'plot(x,exp(x)),',... 'end']);

p2=uicontrol('parent',h0,... 'style','pushbutton',... 'position',[270 100 60 40],... 'string','关闭',... 'callback','close'); l1=uicontrol('parent',h0,... 'style','listbox',...

'position',[10 300 80 80],... 'string','sin(x)|cos(x)|exp(x)',... 'value',1,... 'max',0.5,... 'min',0);

f2=uicontrol('parent',h0,... 'style','text',... 'string','选择函数',... 'fontsize',10,...

'position',[10 380 80 20]); r1=uicontrol('style','radio',... 'string','grid on',... 'value',0,...

'position',[10 100 60 20],... 'callback',[... 'grid on,',...

'set(r1,''value'',1);,',... 'set(r2,''value'',0)']); r2=uicontrol('style','radio',... 'string','grid off',... 'position',[10 80 60 20],... 'value',1,... 'callback',[... 'grid off,',...

'set(r2,''value'',1);,',... 'set(r1,''value'',0)']); e1=uicontrol('parent',h0,... 'style','edit',... 'string',0,...

'position',[20 210 60 20],... 'horizontalalignment','right'); e2=uicontrol('parent',h0,... 'style','edit',... 'string','3',...

'position',[20 150 60 20],... 'horizontalalignment','right'); t1=uicontrol('parent',h0,... 'style','text',... 'string','x from',... 'fontsize',10,...

'position',[20 230 60 20],... 'horizontalalignment','center'); t2=uicontrol('parent',h0,... 'style','text',... 'string','to',... 'fontsize',10,...

'position',[20 170 60 20],... 'horizontalalignment','center');

实例51:可设置函数曲线图视角的用户界面 h0=figure('toolbar','none',... 'position',[198 56 408 468],... 'name','实例51');

h1=axes('parent',h0,...

'position',[0.15 0.45 0.7 0.5],... 'visible','off');

[x,y]=meshgrid(-8:0.5:8); r=sqrt(x.^2+y.^2)+eps; z=sin(r)./r; f1=surf(x,y,z); shading interp view(-50,30) camlight left colormap([1 0 0]) fv=get(h0,'colormap'); ifv=fv;

p1=uicontrol('parent',h0,... 'style','pushbutton',... 'string','重置',...

'position',[280 120 50 30],... 'callback',[...

'set(s1,''value'',ifv(1));,',... 'set(s2,''value'',ifv(2));,',... 'set(s3,''value'',ifv(3));,',... 'set(h0,''colormap'',ifv)']); p2=uicontrol('parent',h0,... 'style','pushbutton',... 'string','关闭',...

'position',[280 60 50 30],... 'callback','close'); s1=uicontrol('parent',h0,... 'style','slider',... 'min',0,... 'max',1,... 'value',fv(1),...

'position',[20 150 200 20],... 'callback',[...

's1k=get(s1,''value'');,',... 'fv(1)=s1k;,',...

'set(h0,''colormap'',fv);']);

Matlab100个实例程序

y=sin(x);plot(x,y);xlabel('x');ylabel('y');title('坐标轴范围的改变');h=get(gca,'xlim');k=get(gca,'ylim');e1=uicontrol('parent',h0,...'style','edit',...'string
推荐度:
点击下载文档文档为doc格式
4vva413ors5o77k30e8m0fvqu4yw2700pfg
领取福利

微信扫码领取福利

微信扫码分享