数模论坛

 找回密码
 注-册-帐-号
搜索
热搜: 活动 交友 discuz
楼主: 宝宝

【编程学习】matlab实用程序百例

  [复制链接]
 楼主| 发表于 2004-6-1 18:08:11 | 显示全部楼层
<><FONT size=1><b><EM>实例47:曲线标记</EM></b></FONT></P><>h0=figure('toolbar','none',...
    'position',[198 56 408 468],...
    'name','my second gui');
h1=axes('parent',h0,...
    'position',[0.15 0.45 0.7 0.5],...
    'visible','on');
x=0:0.1:2*pi;
k=plot(x,sin(x),'*');
xlabel('自变量X');
ylabel('函数值Y');
title('标记类型的改变');
p1=uicontrol('parent',h0,...
    'style','pushbutton',...
    'string','+',...
    'fontsize',20,...
    'foregroundcolor',[1 1 1],...
    'backgroundcolor',[0 0 0],...
    'position',[60 100 50 20],...
    'callback','set(k,''marker'',''+'')');
p2=uicontrol('parent',h0,...
    'style','pushbutton',...
    'string','o',...
    'fontsize',20,...
    'foregroundcolor',[1 1 1],...
    'backgroundcolor',[0 0 0],...
    'position',[170 100 50 20],...
    'callback','set(k,''marker'',''o'')');
p3=uicontrol('parent',h0,...
    'style','pushbutton',...
    'string','x',...
    'fontsize',20,...
    'foregroundcolor',[1 1 1],...
    'backgroundcolor',[0 0 0],...
    'position',[280 100 50 20],...
    'callback','set(k,''marker'',''x'')');
p4=uicontrol('parent',h0,...
    'style','pushbutton',...
    'backgroundcolor',[1 1 1],...
    'fontsize',20,...
    'fontweight','demi',...
    'string','关闭',...
    'position',[150 30 80 60],...
    'callback','close');
t1=uicontrol('parent',h0,...
    'style','text',...
    'string','星号',...
    'fontsize',12,...
    'fontweight','demi',...
    'position',[60 120 50 20]);
t2=uicontrol('parent',h0,...
    'style','text',...
    'string','圆圈',...
    'fontsize',12,...
    'fontweight','demi',...
    'position',[170 120 50 20]);
t3=uicontrol('parent',h0,...
    'style','text',...
    'string','叉号',...
    'fontsize',12,...
    'fontweight','demi',...
    'position',[280 120 50 20]);</P>
 楼主| 发表于 2004-6-1 18:08:53 | 显示全部楼层
<><FONT size=1><b><EM>实例48:修改曲型</EM></b></FONT></P><>h0=figure('toolbar','none',...
    'position',[198 56 408 468],...
    'name','实例48');
h1=axes('parent',h0,...
    'position',[0.15 0.45 0.7 0.5],...
    'visible','on');
x=0:0.1:2*pi;
k=plot(x,sin(x));
xlabel('自变量X');
ylabel('函数值Y');
title('线型的改变');
p1=uicontrol('parent',h0,...
    'style','pushbutton',...
    'string','-.',...
    'fontsize',20,...
    'foregroundcolor',[1 1 1],...
    'backgroundcolor',[0 0 0],...
    'position',[60 100 50 20],...
    'callback','set(k,''linestyle'',''-.'')');
p2=uicontrol('parent',h0,...
    'style','pushbutton',...
    'string',':',...
    'fontsize',20,...
    'foregroundcolor',[1 1 1],...
    'backgroundcolor',[0 0 0],...
    'position',[170 100 50 20],...
    'callback','set(k,''linestyle'','':'')');
p3=uicontrol('parent',h0,...
    'style','pushbutton',...
    'string','-',...
    'fontsize',20,...
    'foregroundcolor',[1 1 1],...
    'backgroundcolor',[0 0 0],...
    'position',[280 100 50 20],...
    'callback','set(k,''linestyle'',''-'')');
p4=uicontrol('parent',h0,...
    'style','pushbutton',...
    'backgroundcolor',[1 1 1],...
    'fontsize',20,...
    'fontweight','demi',...
    'string','关闭',...
    'position',[150 30 80 60],...
    'callback','close');
t1=uicontrol('parent',h0,...
    'style','text',...
    'string','点划线',...
    'fontsize',12,...
    'fontweight','demi',...
    'position',[60 120 50 20]);
t2=uicontrol('parent',h0,...
    'style','text',...
    'string','虚线',...
    'fontsize',12,...
    'fontweight','demi',...
    'position',[170 120 50 20]);
t3=uicontrol('parent',h0,...
    'style','text',...
    'string','实线',...
    'fontsize',12,...
    'fontweight','demi',...
    'position',[280 120 50 20]);</P>
 楼主| 发表于 2004-6-1 18:09:09 | 显示全部楼层
<><FONT size=1><b><EM>实例48:修改曲型</EM></b></FONT></P><>h0=figure('toolbar','none',...
    'position',[198 56 408 468],...
    'name','实例48');
h1=axes('parent',h0,...
    'position',[0.15 0.45 0.7 0.5],...
    'visible','on');
x=0:0.1:2*pi;
k=plot(x,sin(x));
xlabel('自变量X');
ylabel('函数值Y');
title('线型的改变');
p1=uicontrol('parent',h0,...
    'style','pushbutton',...
    'string','-.',...
    'fontsize',20,...
    'foregroundcolor',[1 1 1],...
    'backgroundcolor',[0 0 0],...
    'position',[60 100 50 20],...
    'callback','set(k,''linestyle'',''-.'')');
p2=uicontrol('parent',h0,...
    'style','pushbutton',...
    'string',':',...
    'fontsize',20,...
    'foregroundcolor',[1 1 1],...
    'backgroundcolor',[0 0 0],...
    'position',[170 100 50 20],...
    'callback','set(k,''linestyle'','':'')');
p3=uicontrol('parent',h0,...
    'style','pushbutton',...
    'string','-',...
    'fontsize',20,...
    'foregroundcolor',[1 1 1],...
    'backgroundcolor',[0 0 0],...
    'position',[280 100 50 20],...
    'callback','set(k,''linestyle'',''-'')');
p4=uicontrol('parent',h0,...
    'style','pushbutton',...
    'backgroundcolor',[1 1 1],...
    'fontsize',20,...
    'fontweight','demi',...
    'string','关闭',...
    'position',[150 30 80 60],...
    'callback','close');
t1=uicontrol('parent',h0,...
    'style','text',...
    'string','点划线',...
    'fontsize',12,...
    'fontweight','demi',...
    'position',[60 120 50 20]);
t2=uicontrol('parent',h0,...
    'style','text',...
    'string','虚线',...
    'fontsize',12,...
    'fontweight','demi',...
    'position',[170 120 50 20]);
t3=uicontrol('parent',h0,...
    'style','text',...
    'string','实线',...
    'fontsize',12,...
    'fontweight','demi',...
    'position',[280 120 50 20]);</P>
 楼主| 发表于 2004-6-1 18:09:15 | 显示全部楼层
<><FONT size=1><b><EM>实例48:修改曲型</EM></b></FONT></P><>h0=figure('toolbar','none',...
    'position',[198 56 408 468],...
    'name','实例48');
h1=axes('parent',h0,...
    'position',[0.15 0.45 0.7 0.5],...
    'visible','on');
x=0:0.1:2*pi;
k=plot(x,sin(x));
xlabel('自变量X');
ylabel('函数值Y');
title('线型的改变');
p1=uicontrol('parent',h0,...
    'style','pushbutton',...
    'string','-.',...
    'fontsize',20,...
    'foregroundcolor',[1 1 1],...
    'backgroundcolor',[0 0 0],...
    'position',[60 100 50 20],...
    'callback','set(k,''linestyle'',''-.'')');
p2=uicontrol('parent',h0,...
    'style','pushbutton',...
    'string',':',...
    'fontsize',20,...
    'foregroundcolor',[1 1 1],...
    'backgroundcolor',[0 0 0],...
    'position',[170 100 50 20],...
    'callback','set(k,''linestyle'','':'')');
p3=uicontrol('parent',h0,...
    'style','pushbutton',...
    'string','-',...
    'fontsize',20,...
    'foregroundcolor',[1 1 1],...
    'backgroundcolor',[0 0 0],...
    'position',[280 100 50 20],...
    'callback','set(k,''linestyle'',''-'')');
p4=uicontrol('parent',h0,...
    'style','pushbutton',...
    'backgroundcolor',[1 1 1],...
    'fontsize',20,...
    'fontweight','demi',...
    'string','关闭',...
    'position',[150 30 80 60],...
    'callback','close');
t1=uicontrol('parent',h0,...
    'style','text',...
    'string','点划线',...
    'fontsize',12,...
    'fontweight','demi',...
    'position',[60 120 50 20]);
t2=uicontrol('parent',h0,...
    'style','text',...
    'string','虚线',...
    'fontsize',12,...
    'fontweight','demi',...
    'position',[170 120 50 20]);
t3=uicontrol('parent',h0,...
    'style','text',...
    'string','实线',...
    'fontsize',12,...
    'fontweight','demi',...
    'position',[280 120 50 20]);</P>
 楼主| 发表于 2004-6-1 18:10:00 | 显示全部楼层
<><FONT size=1><b><EM>实例49:指定坐标轴范围</EM></b></FONT></P><>h0=figure('toolbar','none',...
    'position',[198 56 408 468],...
    'name','实例49');
h1=axes('parent',h0,...
    'position',[0.15 0.45 0.7 0.5],...
    'visible','on');
x=0:0.1:2*pi;
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');</P>
 楼主| 发表于 2004-6-1 18:10:40 | 显示全部楼层
<><FONT size=1><b><EM>实例50:绘制不同函数曲线的用户界面</EM></b></FONT></P><>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');</P>
 楼主| 发表于 2004-6-1 18:11:45 | 显示全部楼层
<><FONT size=1><b><EM>实例51:可设置函数曲线图视角的用户界面</EM></b></FONT></P><>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);']);
t1=uicontrol('parent',h0,...
    'style','text',...
    'string','改变红色成分',...
    'position',[20 170 100 20]);
s2=uicontrol('parent',h0,...
    'style','slider',...
    'min',0,...
    'max',1,...
    'value',fv(2),...
    'position',[20 100 200 20],...
    'callback',[...
        's2k=get(s2,''value'');,',...
        'fv(2)=s2k;,',...
        'set(h0,''colormap'',fv);']);
t2=uicontrol('parent',h0,...
    'style','text',...
    'string','改变绿色成分',...
    'position',[20 120 100 20]);
s3=uicontrol('parent',h0,...
    'style','slider',...
    'min',0,...
    'max',1,...
    'value',fv(3),...
    'position',[20 50 200 20],...
    'callback',[...
        's3k=get(s3,''value'');,',...
        'fv(3)=s3k;,',...
        'set(h0,''colormap'',fv);']);
t1=uicontrol('parent',h0,...
    'style','text',...
    'string','改变蓝色成分',...
    'position',[20 70 100 20]);
</P>
 楼主| 发表于 2004-6-1 18:11:48 | 显示全部楼层
<><FONT size=1><b><EM>实例51:可设置函数曲线图视角的用户界面</EM></b></FONT></P><>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);']);
t1=uicontrol('parent',h0,...
    'style','text',...
    'string','改变红色成分',...
    'position',[20 170 100 20]);
s2=uicontrol('parent',h0,...
    'style','slider',...
    'min',0,...
    'max',1,...
    'value',fv(2),...
    'position',[20 100 200 20],...
    'callback',[...
        's2k=get(s2,''value'');,',...
        'fv(2)=s2k;,',...
        'set(h0,''colormap'',fv);']);
t2=uicontrol('parent',h0,...
    'style','text',...
    'string','改变绿色成分',...
    'position',[20 120 100 20]);
s3=uicontrol('parent',h0,...
    'style','slider',...
    'min',0,...
    'max',1,...
    'value',fv(3),...
    'position',[20 50 200 20],...
    'callback',[...
        's3k=get(s3,''value'');,',...
        'fv(3)=s3k;,',...
        'set(h0,''colormap'',fv);']);
t1=uicontrol('parent',h0,...
    'style','text',...
    'string','改变蓝色成分',...
    'position',[20 70 100 20]);
</P>
 楼主| 发表于 2004-6-1 18:11:49 | 显示全部楼层
<><FONT size=1><B><EM>实例51:修改函数曲线图颜色的用户界面</EM></B></FONT></P>
<>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);']);
t1=uicontrol('parent',h0,...
    'style','text',...
    'string','改变红色成分',...
    'position',[20 170 100 20]);
s2=uicontrol('parent',h0,...
    'style','slider',...
    'min',0,...
    'max',1,...
    'value',fv(2),...
    'position',[20 100 200 20],...
    'callback',[...
        's2k=get(s2,''value'');,',...
        'fv(2)=s2k;,',...
        'set(h0,''colormap'',fv);']);
t2=uicontrol('parent',h0,...
    'style','text',...
    'string','改变绿色成分',...
    'position',[20 120 100 20]);
s3=uicontrol('parent',h0,...
    'style','slider',...
    'min',0,...
    'max',1,...
    'value',fv(3),...
    'position',[20 50 200 20],...
    'callback',[...
        's3k=get(s3,''value'');,',...
        'fv(3)=s3k;,',...
        'set(h0,''colormap'',fv);']);
t1=uicontrol('parent',h0,...
    'style','text',...
    'string','改变蓝色成分',...
    'position',[20 70 100 20]);
</P>
 楼主| 发表于 2004-6-1 18:14:08 | 显示全部楼层
<>实例52:<b><EM><FONT size=1>可设置函数曲线图视角的用户界面</FONT></EM></b></P><>h0=figure('toolbar','none',...
    'position',[198 56 408 468],...
    'name','实例52');
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 interp
view([-60 30])
fv=get(h1,'view');
fv2=fv;
camlight left
sh1=uicontrol('parent',h0,...
    'style','slider',...
    'max',1,...
    'min',-1,...
    'value',fv(1)/180,...
    'position',[20 150 200 20],...
    'callback',[...
        'fv(1)=90*get(sh1,''value'');,',...
        'set(h1,''view'',[fv(1) fv(2)]),',...
        'set(ed1,''string'',fv(1))']);   
text1=uicontrol('parent',h0,...
    'style','text',...
    'string','方位角的变化滑标',...
    'position',[20 170 200 20]);
sh2=uicontrol('parent',h0,...
    'style','slider',...
    'max',1,...
    'min',-1,...
    'value',fv(2)/180,...
    'position',[20 90 200 20],...
    'callback',[...
        'fv(2)=90*get(sh2,''value'');,',...
        'set(h1,''view'',[fv(1) fv(2)]),',...
        'set(ed2,''string'',fv(2))']);
text2=uicontrol('parent',h0,...
    'style','text',...
    'string','仰角的变化滑标',...
    'position',[20 110 200 20]);
ed1=uicontrol('parent',h0,...
    'style','edit',...
    'string',fv(1),...
    'position',[30 30 50 20]);
text3=uicontrol('parent',h0,...
    'style','text',...
    'string','方位角的数值',...
    'position',[20 50 80 20]);
ed2=uicontrol('parent',h0,...
    'style','edit',...
    'string',fv(2),...
    'position',[150 30 50 20]);
text4=uicontrol('parent',h0,...
    'style','text',...
    'string','仰角的数值',...
    'position',[135 50 80 20]);
pf1=uicontrol('parent',h0,...
    'style','pushbutton',...
    'string','重置',...
    'position',[280 120 50 30],...
    'callback',[...
        'set(h1,''view'',fv2),',...
        'set(sh1,''value'',fv2(1)/180),',...
        'set(sh2,''value'',fv2(2)/180),',...
        'set(ed1,''string'',fv2(1)),',...
        'set(ed2,''string'',fv2(2))']);
pf2=uicontrol('parent',h0,...
    'style','pushbutton',...
    'string','关闭',...
    'position',[280 60 50 30],...
    'callback','close');
</P>
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

小黑屋|手机版|Archiver|数学建模网 ( 湘ICP备11011602号 )

GMT+8, 2024-4-20 12:31 , Processed in 0.055881 second(s), 12 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表