【问题标题】:How can I program a GUI in MATLAB? [closed]如何在 MATLAB 中编写 GUI? [关闭]
【发布时间】:2010-11-10 02:01:33
【问题描述】:

我需要在 MATLAB 中为我的项目创建一个 GUI。我到处寻找如何编写 GUI 的示例,但找不到很多。 MATLAB GUI 编程有哪些好的网站或技术?

【问题讨论】:

    标签: matlab user-interface matlab-guide


    【解决方案1】:

    Matt Fig 发布到 MathWorks File Exchange 的这些 41 complete GUI examples 是一个很好的起点。提交的内容甚至是Pick of the Week

    【讨论】:

      【解决方案2】:

      我最近不得不编写一个简单的 GUI 来控制一些绘图。我不确切知道您的任务是什么,但这里有一些基本代码可以帮助您入门。这会创建两个数字;图 1 具有控件,图 2 具有 y=x^p 的图。您在框中输入 p 的值,然后按 enter 进行注册并重新绘制;然后按下按钮重置为默认 p=1。

          function SampleGUI()
          x=linspace(-2,2,100);
          power=1;
          y=x.^power;
          ctrl_fh = figure; % controls figure handle
          plot_fh = figure; % plot figure handle
          plot(x,y); 
          % uicontrol handles:
          hPwr = uicontrol('Style','edit','Parent',... 
                               ctrl_fh,...
                               'Position',[45 100 100 20],...
                               'String',num2str(power),...
                               'CallBack',@pwrHandler);
      
          hButton = uicontrol('Style','pushbutton','Parent',ctrl_fh,...  
                              'Position',[45 150 100 20],...
                              'String','Reset','Callback',@reset); 
      
          function reset(source,event,handles,varargin) % boilerplate argument string
              fprintf('resetting...\n');
              power=1;
              set(hPwr,'String',num2str(power));
              y=x.^power;
              compute_and_draw_plot();
          end
      
          function pwrHandler(source,event,handles,varargin) 
              power=str2num(get(hPwr,'string'));
              fprintf('Setting power to %s\n',get(hPwr,'string'));
              compute_and_draw_plot();
          end
      
          function compute_and_draw_plot()
              y=x.^power;
              figure(plot_fh); plot(x,y);
          end
      end
      

      GUI 背后的基本思想是,当您操作控件时,它们会调用“回调”函数,即事件处理程序;这些函数能够使用控件句柄和 set/get 方法通过控件进行交互,以获取或更改它们的属性。

      要查看可用属性列表,请仔细阅读 Matlab 文档网站 (http://www.mathworks.com/access/helpdesk/help/techdoc/infotool/hgprop/doc_frame.html) 上信息丰富的 Handle Graphics Property Browser;单击 UI 对象(或您需要的任何其他对象)。

      希望这会有所帮助!

      【讨论】:

        【解决方案3】:

        这是我制作的有关制作 MATLAB GUI 的所有视频

        http://blogs.mathworks.com/videos/category/gui-or-guide/

        【讨论】:

          【解决方案4】:

          您需要去的第一个地方是 Creating Graphical User Interfaces 上的 Matlab 帮助 .

          然后,你可以观看this tutorial videothis one

          This tutorial也不错。

          【讨论】:

            猜你喜欢
            • 2023-03-21
            • 1970-01-01
            • 2016-05-24
            • 2020-10-08
            • 1970-01-01
            • 1970-01-01
            • 2011-07-23
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多