前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Matlab实用程序--图形界面应用5

Matlab实用程序--图形界面应用5

作者头像
用户9925864
发布2022-07-27 09:23:00
3330
发布2022-07-27 09:23:00
举报
文章被收录于专栏:算法工程师的学习日志

实例47:曲线标记

代码语言:javascript
复制
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]);

实例48:修改曲型

代码语言:javascript
复制
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]);

实例49:指定坐标轴范围

代码语言:javascript
复制
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');

实例50:绘制不同函数曲线的用户界面

代码语言:javascript
复制
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');
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-09-27,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 算法工程师的学习日志 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档