• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

我的matlab 的第一个gui工程

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

注意,在设置position属性之前一定要先设置 units,不然会出错,无法显示radiobutton,同时,注意callback函数的特质与fcn的一些特殊规定,比如使用maxvalue,总体而言,matlab功能强大,确实值得一试,也算打了一天这个东西。

注意,如果不设置units,或者设置units为normalized,那么matlab的长1默认为150 像素,宽 60

function mygui
s.hf = figure;
set(s.hf,\'toolbar\',\'figure\',\'menubar\',\'none\',\'numbertitle\',\'off\',\'name\',\'example window\',\'units\',\'normalized\',\'position\',[0.3 0.4 0.6 0.5]);
s.haxes = axes(\'parent\',s.hf,\'position\',[0.1 0.1 0.5 0.8]);
x=0:pi/50:2*pi;
y = sin(x);
axes(s.haxes);
s.plot = plot(x,y,\'b\',\'linewidth\',1.5);
set(gca,\'fontangle\',\'italic\',\'xcolor\',[1 0 0]);
grid on
title(\'我的坐标轴\');
xlabel(\'x_轴\');
ylabel(\'y_轴\');
s.hgroup = uibuttongroup(\'parent\',s.hf,\'title\',\'栅格控制\',\'units\',\'normalized\',\'position\',[0.7 0.7 0.1 0.2]);
s.hRadio1 = uicontrol(\'parent\',s.hgroup,\'style\',\'radiobutton\',\'units\',\'normalized\',\'string\',\'grid on\',\'tag\',\'radiobutton1\',\'position\',[0.1 0.7 0.8 0.2]);
s.hRadio2 = uicontrol(\'parent\',s.hgroup,\'style\',\'radiobutton\',\'string\',\'grid off\',\'units\',\'normalized\',\'tag\',\'radiobutton2\',\'position\',[0.1 0.1 0.8 0.2]);
s.text1 = uicontrol(\'parent\',s.hf,\'style\',\'text\',\'string\',\'曲线颜色\',\'units\',\'normalized\',\'position\',[0.7 0.6 0.1 0.05]);
s.list = uicontrol(\'parent\',s.hf,\'style\',\'listbox\',...
    \'string\',{\'r\',\'g\',\'b\'},...
    \'units\',\'normalized\',...
    \'position\',[0.805 0.55 0.1 0.1]);
s.text2 = uicontrol(\'parent\',s.hf,\'style\',\'text\',\'string\',\'曲线线型\',\'units\',\'normalized\',\'position\',[0.7 0.45 0.1 0.05]);
s.pop = uicontrol(\'parent\',s.hf,\'style\',\'popupmenu\',\'string\',{\'-\';\'- -\';\':\';\'- .\';\'none\'},\'units\',\'normalized\',\'position\',[0.805 0.4 0.1 0.1]);
set(s.hgroup,\'SelectionChangeFcn\',...
    {@buttongroup_selection,s});
set(s.list,\'callback\',{@list_callback,s});
set(s.pop,\'callback\',{@pop_callback,s});
s.menu = uimenu(\'Label\',\'曲线颜色\');
menu1=uimenu(s.menu,\'Label\',\'红色\',\'Foregroundcolor\',[1,0,0],\'Callback\',{@menu_callback,s});
menu2=uimenu(s.menu,\'Label\',\'绿色\',\'Foregroundcolor\',[0,1,0],\'Callback\',{@menu_callback,s});
menu3=uimenu(s.menu,\'Label\',\'蓝色\',\'Foregroundcolor\',[0,0,1],\'Callback\',{@menu_callback,s});
s.toolbar = uitoolbar(s.hf);
a = rand(16,16,3);
s.toggletool = uitoggletool(s.toolbar,\'CData\',a,\'TooltipString\',\'栅格控制\');
set(s.toggletool,\'oncallback\',{@grid_on_callback,s});
set(s.toggletool,\'offcallback\',{@grid_off_callback,s});
function grid_on_callback(hobject,event,s)
set(s.haxes,\'xgrid\',\'on\',\'ygrid\',\'on\');

function grid_off_callback(hobject,event,s)
set(s.haxes,\'xgrid\',\'off\',\'ygrid\',\'off\');

function menu_callback(hobject,eventdata,s)
value = get(hobject,\'position\');
switch value
    case 1
        set(s.plot,\'color\',\'r\');
    case 2
        set(s.plot,\'color\',\'g\');
    case 3
        set(s.plot,\'color\',\'b\');
end


function buttongroup_selection(hobject,eventdata,s)
tag = get(eventdata.NewValue,\'tag\');
switch tag
    case \'radiobutton1\'
        set(s.haxes,\'xgrid\',\'on\',\'ygrid\',\'on\');
    case \'radiobutton2\'
        set(s.haxes,\'xgrid\',\'off\',\'ygrid\',\'off\');
end

function list_callback(object,event,s)
value = get(object,\'value\');
switch value
    case 1
        set(s.plot,\'color\',\'r\');
    case 2
        set(s.plot,\'color\',\'g\');
    case 3
        set(s.plot,\'color\',\'b\');
end

function pop_callback(hobject,~,s)
value = get(hobject,\'value\');
switch value
    case 1
        set(s.plot,\'linestyle\',\'-\',\'marker\',\'none\');
    case 2
        set(s.plot,\'linestyle\',\'- -\',\'marker\',\'none\');
    case 3
        set(s.plot,\'linestyle\',\':\',\'marker\',\'none\');
    case 4
        set(s.plot,\'linestyle\',\'- .\',\'marker\',\'none\');
     case 5
        set(s.plot,\'linestyle\',\'none\',\'marker\',\'none\');
end




      
      

  


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
matlab GUI之 -- 绘图发布时间:2022-07-18
下一篇:
matlab演奏最炫民族风的代码注释 - KK4SBB发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap