关于matlab中的GUI的 Pop-up Menu

合集下载

matlab中gui教程

matlab中gui教程

11 图形用户界面(GUI )制作用户界面(或接口)是指:人与机器(或程序)之间交互作用的工具和方法。

如键盘、鼠标、跟踪球、话筒都可成为与计算机交换信息的接口。

图形用户界面(Graphical User Interfaces ,GUI )则是由窗口、光标、按键、菜单、文字说明等对象(Objects )构成的一个用户界面。

用户通过一定的方法(如鼠标或键盘)选择、激活这些图形对象,使计算机产生某种动作或变化,比如实现计算、绘图等。

假如读者所从事的数据分析、解方程、计算结果可视工作比较单一,那么一般不会考虑GUI 的制作。

但是如果读者想向别人提供应用程序,想进行某种技术、方法的演示,想制作一个供反复使用且操作简单的专用工具,那么图形用户界面也许是最好的选择之一。

MATLAB 为表现其基本功能而设计的演示程序demo 是使用图形界面的最好范例。

MATLAB 的用户,在指令窗中运行demo 打开那图形界面后,只要用鼠标进行选择和点击,就可浏览那丰富多彩的内容。

即便比较熟悉MATLAB 的读者,在他初次编写GUI 程序时,也会感到棘手。

为使读者获得制作自己GUI 的体验,本章“入门”节提供了一个简单的示例。

读者只要输入所提供的程序,就可引出相应的界面。

本章第2节叙述图形用户界面的设计原则和一般制作步骤。

第3、4节分别介绍用户菜单、用户控件的制作。

出于“由浅入深”的考虑,前4节制作GUI 是通过M 脚本文件实现的。

利用M 函数文件制作GUI ,需要解决数据传递问题,为此专设第5节给予阐述和示例。

MATLAB 5.x 版为方便用户制作图形界面,提供了一个交互式的设计工具guide 。

关于该工具的使用方法,被放在第6节中,以一个综合例题为设计目标逐步展开。

在此提醒读者,假如要比较准确的理解本章程序和掌握本章内容,请先阅读第10章关于图柄的内容。

11.1 入门【*例11.1-1】对于传递函数为1212++=s s G ζ的归一化二阶系统,制作一个能绘制该系统单位阶跃响应的图形用户界面。

Matlab GUI 设计说明报告

Matlab GUI 设计说明报告

引言我们小组采用的开发环境为:Matlab 7.0设计的GUI界面通常在开发一个实际应用的程序时会尽量做到界面友好,最常使用的方法就是使用图形用户界面GUI。

建立这样一个界面友好、占用资源少、高性能、便于移植、可配置的GUI界面设计,能够使用户的学习和使用更为方便容易。

用户不需要知道后台的应用程序究竟是怎样执行各种命令的,而只需了解可见界面组件的使用方法;只要通过与界面交流就可以使指定的行为得到正确的执行,对输入的信息进行一系列的处理。

利用Matlab设计《正则化参数的选择方法》的GUI界面,能够方便直观地对参数选择很好的表达出来。

及时观察参数变化过程中的正则化参数的变化选取,对于研究一些信号、图形、图像处理技术具有十分重要的参考意义。

目录摘要一、任务安排二、GUI界面分析三、功能分析四、正则化参数选择方法4.1、一维正则化参数选择方法4.1.1、模型假设和初步结果4.1.2、Rand_trace4.1.3、Tikh_indicators4.1.4、Tsvd_indicatiors4.1.5、L_curvve4.1.6、Generalized Cross Validation4.2、二维正则化参数选择方法4.2.1、CL_Tikh_4.2.2、CL_Tsvd_4.2.3、GCV_data2D4.2.4、GCV_Tikh4.2.5、GCV_Tsvd_五、总结六、参考文献摘要正则化方法是否有效和成功直接依赖于正则化参数的选取.在许多不适定问题的计算中,正则化参数的选取往往是经验的或者先验的,这无论从实际计算和理论研究两个方面来说都不是令人满意的.另一方面,在反问题求解中通过不断试验来获得一个可行的正则化参数也是非常耗时的.因此若能找到有效的方法来选取正则化参数,这无疑将会大大节约计算代价,进一步提升正则化方法的效能. 本文主要研究的是利用模型函数的思想方法来确定正则化参数.首先,研究在算子与观测数据(算子方程的右端项)都非精确条件下的Tikhonov正则化方法中正则化参数的选取问题,提出了一种简单迭代法,并利用模型函数的思想方法证明了迭代序列是收敛的.其次,将正则化参数选取的L-曲线准则归结为泛函极值问题,基于模型函数的思想提出了求解所归结出的泛函极值问题的迭代算法,从而获得正则化参数的近似值.最后,对所提出的方法进行了数值模拟.具体从以下几个方面展开:【关键字】正则化参数模型函数方法L-曲线准则广义交叉验证一、任务安排这次专题软件开发训练小组成员共4人,分工明确,每个成员都收获很多。

matlab中GUI的使用

matlab中GUI的使用

今天由于要帮一朋友用matlab处理一幅图片,处理图片的要求其实很简单,就是把图片加载进matlab中,然后显示出想要的某一列的趋势图来。

如果用代码写的话,程序如下:x=imread(‘文件路径\*.jpg’);figure(1);plot(x(:,100)); %假如要显示的是图像的第100列的趋势图显示效果如下图所示:虽然用M文件写两句很简单,不过带着感情,追求更好是我们永恒的动力,首先用M文件时候人机界面不友好,的看很多的代码,尤其对不太熟悉M编程的的人而言即使很简单也看着比较郁闷,因此我们接下来用matlab中的GUI来完成这个简单的例子,当然编程起来比这个复杂多,但是对使用者而言确很简单清楚。

这个就如同VC中的MFC和WINDOWSFORMS一样。

做成的都是人机交互界面。

不废话了,看例子。

首先打开MATLAB,要新建一个MATLAB GUI 程序有三种方法,这里我直接在命令窗口里输入guide,新建一个空的GUI程序,选择如下图:新建好的GUI编程界面如下图,上面无非就是菜单,工具,还有编程用到的控件,还有编程的用户窗口。

这个和LABVIEW有点像。

不过LABVIEW的前面板都是用控件拖出来的,后面板也是拖控件画出来的。

而GUI的显示界面是拖控件画出来的,其中一些属性参数要设置下,而后面的执行这些控件的都是写的M函数,即后面板都是要写代码的,这个比LABVIEW单纯的画程序要难,当然灵活性也大,不过个人感觉没一个简单的,都难呀。

至于上面控件的意思,怎么拖请自己看吧,若学过MFC或者WINDOWSFORMS的人就会很容易理解的,这之间是太像了,呵呵。

我们的目的是显示图片,并且显示需要的某一列的趋势图。

为了使人机交互更好点,我们可以使加载图片时和我们选择打开文件夹那样完成,即自己选择路径,而不用每次在M文件里改路径。

还有我们要求在加载图片完成时立马显示出这幅图片的大小信息,即多少行,多少列。

Matlab技术GUI设计方法

Matlab技术GUI设计方法

Matlab技术GUI设计方法Matlab是一种强大的数学软件,广泛应用于科学计算、数据分析和可视化等领域。

在使用Matlab进行数据处理和算法开发时,GUI(Graphical User Interface,图形用户界面)常常是必不可少的工具。

本文将介绍一些Matlab技术GUI设计方法,帮助读者快速掌握GUI设计的基本原理和实现技巧。

一、GUI设计的基本原理1. 用户需求分析在设计GUI之前,首先需要明确用户的需求。

这包括用户需要处理的数据类型、使用的功能和界面布局等。

通过与用户交流和需求分析,可以明确GUI的设计目标,为后续的设计工作提供指导。

2. 界面布局设计界面布局是GUI设计的基础,决定了用户与软件交互的方式。

在设计界面布局时,可以使用Matlab提供的GUI设计工具来快速设计界面,也可以采用编程的方式来实现自定义的界面布局。

无论是使用哪种方式,都需要考虑界面的美观性和易用性。

3. 功能模块设计功能模块是GUI设计的核心,决定了用户可以通过界面进行的操作。

在设计功能模块时,可以使用Matlab提供的各种函数和工具箱来实现数据处理、算法运算等功能。

同时,还可以根据用户的需求,添加自定义的功能模块,提高GUI的灵活性和扩展性。

4. 事件响应设计事件响应是GUI设计中的重要部分,用于实现用户和软件之间的交互。

在Matlab中,可以通过编写回调函数来实现事件的响应。

回调函数是Matlab中的一种特殊函数,用于处理用户的输入和界面的变化。

通过编写适当的回调函数,可以使GUI实现与用户的实时交互,并根据用户的操作进行相应的数据处理和算法运算。

二、GUI设计的实现技巧1. 使用Matlab提供的GUI设计工具Matlab提供了一系列的GUI设计工具,如GUIDE(GUI Design Environment)、App Designer等。

这些工具提供了丰富的界面组件和布局选项,可以帮助用户快速设计GUI界面。

Matlab_GUI的菜单和工具栏常用操作

Matlab_GUI的菜单和工具栏常用操作
具栏
1) GUIDE开发界面
在对应的m文件中找到 function Main_OpeningFcn(hObject, eventdata, handles, varargin)
3. 菜单项访问
? 获取菜单句柄 在matlab的函数中要对某个菜单进行访问,必须获得该菜单的句柄。 如果是在菜单的回调函数里面,hObject就是该菜单的句柄; 2如果是在其他的函数里面要获得某一菜单的句柄,比如选中工具栏上的ZoomIn按
钮,按钮处于被按下状态,同时要设置对应菜单项view->Zoom-Zoom In 为选中状
8. 设置figure工具栏按钮的状态 % get toolbar handle hToolbar = findall(gcf,'Type','uitoolbar'); if isempty(hToolbar), return, end % get all children hChildren = allchild(hToolbar); if isempty(hChildren), return,end hTags = get(hChildren, 'Tag'); % find "Zoom In" button hb = findobj(hChildren,'Tag','Exploration.ZoomIn'); if isempty(hb),return, end % set state if strcmp(get(hObject, 'Checked'),'on') set(hObject, 'Checked', 'off'); set(hb,'State', 'off'); else set(hObject, 'Checked', 'on'); set(hb,'State', 'on'); end

Matlab界面菜单(uimenu)实例

Matlab界面菜单(uimenu)实例

Matlab界面菜单(uimenu)实例1、获得缺省设置的标准菜单:figure2、隐去标准菜单的两种方法:set(gcf , 'MenuBar','none') ;set (gcf,'menubar',menubar);3、恢复图形窗上标准菜单:set(gcf,'menubar','figure');例1:自制的用户菜单本例演示:如何自制一个带下拉菜单表的用户菜单。

该菜单能使图形窗背景颜色设置为蓝色或红色。

figureh_menu=uimenu(gcf, 'label' , 'Color' ); % 制作用户顶层菜单项 Colorh_submenu1=uimenu(h_menu, 'label' , 'Blue' , 'callback' , 'set(gcf,''Color'',''blue'')' );h_submenu2=uimenu(h_menu, 'label' , 'Red' , 'callback' , 'set(gcf,''Color'',''red'')' );例2:回调属性和菜单名本例的目标:在图形窗上自制一个名为‘Test’的“顶层菜单项”;当用鼠标点击该菜单项时,将产生一个带分格的封闭坐标轴。

通过本例说明:(A)回调属性的运作机理;(B)用户顶层菜单项的制作(C)uimenu属性的设置方法;(D)复杂字符串的构成方法和注意事项。

(1) 在MATLAB指令窗中运行以下程序可产生带分格的封闭坐标轴:grid on, set(gca,'box','on')(2)在 MATLAB 指令窗中用以下eval指令可产生与上面相同的界面eval('grid on, set(gca,''box'',''on'')')(3)产生下图1界面的uimenu有几种不同的方式:书写格式一:直接连续表示法uimenu ('Label','Test','Callback','grid on, set(gca,''box'',''on''),')书写格式二:方括号续行号表示法uimenu ('Label’,’ Test', 'Callback',['grid on,' ,'set(gca,''box'',''on'');'])书写格式三:串变量法Lpv='Test';Cpv=['grid on,','set(gca,''box'',''on''),'];uimenu('Label', Lpv, 'Callback' , Cpv)图1书写格式四:构架表示法bel='Test';PS.Callback=['grid on;','set(gca,''box'',''on'');'];uimenu(PS)例3.设置简捷键或快捷键本例目标:使图2所示菜单成为图3那样,Color 菜单项及其下拉的 Blue 菜单各带一个简捷键,而另一项下拉菜单 Red 带一个快捷键。

MatlabGUI的菜单和工具栏常用操作

MatlabGUI的菜单和工具栏常用操作

Matlab GUI 常用操作菜单1.编辑菜单打开GUIDE,选择工具栏上面的菜单编辑按钮2.添加菜单回调函数(callback)菜单编辑完成保存后,在fig对应的m文件中会自动生成菜单的回调函数声明例如菜单tag名为menuFilePrint,则对应的callback函数为:function menuFilePrint_Callback(hObject, eventdata, handles)可以在该函数内添加代码实现功能。

3.菜单项访问获取菜单句柄在matlab的函数中要对某个菜单进行访问,必须获得该菜单的句柄。

如果是在菜单的回调函数里面,hObject就是该菜单的句柄;如果是在其他的函数里面要获得某一菜单的句柄,比如选中工具栏上的ZoomIn按钮,按钮处于被按下状态,同时要设置对应菜单项view->Zoom-Zoom In 为选中状态,如下图:这里要在按钮“ZoomIn”的callback函数里面实现对菜单menuViewZoomIn的状态设置。

首先得获得菜单的句柄:% first we must get the handle of menuZoomInhFigChildren = allchild(gcf);% menuView handlehMenuView = findobj(hFigChildren,'Tag','menuView');hvc = allchild(hMenuView);% menuViewZoomhViewZoom = findobj(hvc,'Tag','menuViewZoom');hvzc = allchild(hViewZoom);%menuZoomIn handlehZoomIn = findobj(hvzc,'Tag', 'menuZoomIn');获取设置菜单状态得到菜单的句柄后就可以得到菜单当前的状态了:if strcmp(get(hZoomIn, 'Checked'),'on')set(hZoomIn, 'Checked', 'off');elseset(hZoomIn, 'Checked', 'on');end工具栏1.不显示工具栏1)GUIDE开发界面在对应的m文件中找到function Main_OpeningFcn(hObject, eventdata, handles, varargin)在该函数里面添加:set(hObject,'Toolbar','none');2)M文件开发hMainFigure = figure(... % The main GUI figure'MenuBar','none', ...'Toolbar','none', ...'HandleVisibility','callback', ...'Color', get(0,...'defaultuicontrolbackgroundcolor'));2.显示“Figure”工具栏set(hObject,'Toolbar','figure');3.添加自定义工具栏set(hObject,'Toolbar','none');hToolbar = uitoolbar(hObject);hNewPushtool = uipushtool(... % Open toolbar button'Parent',hToolbar,...'TooltipString','New File',...'CData',imread('New.bmp'));'HandleVis ibility','callback', ...'ClickedCallback', @hOpenMenuitemCallback);4.获取工具栏句柄% get toolbar handlehToolbar = findall(gcf,'Type','uitoolbar');if isempty(hToolbar), return, end5.获取figure工具栏按钮的tag值% get toolbar handlehToolbar = findall(gcf,'Type','uitoolbar');if isempty(hToolbar), return, end% get all childrenhChildren = allchild(hToolbar);if isempty(hChildren), return,endhTags = get(hChildren, ‘Tag’);hTags保存了工具栏所有按钮的tag值:6.获取设置figure工具栏按钮的callback函数%reset callback function for "Zoom in"hZoomIn = findobj(hChildren,'Tag','Exploration.ZoomIn');set(hZoomIn,'ClickedCallback',@tbZoomIn_Callback);function tbZoomIn_Callback(hObject, eventdata)% hObject handle to tbZoomIn (see GCBO)% eventdata reserved - to be defined in a future version of MATLA B 7.删除figure工具栏按钮% set figure toolbar firstset(hObject,'Toolbar','figure');% get toolbar handletbh = findall(hObject,'Type','uitoolbar');if isempty(tbh), return, end% toolbar buttons collectionhChildren = allchild(tbh);if isempty(hChildren), return, end% delete data cursor buttonhDeleted = findobj(hChildren,'Tag','Exploration.DataCursor');delete(hDeleted);8.设置figure工具栏按钮的状态% get toolbar handlehToolbar = findall(gcf,'Type','uitoolbar');if isempty(hToolbar), return, end% get all childrenhChildren = allchild(hToolbar);if isempty(hChildren), return,endhTags = get(hChildren, 'Tag');% find "Zoom In" buttonhb = findobj(hChildren,'Tag','Exploration.ZoomIn');if isempty(hb),return, end% set stateif strcmp(get(hObject, 'Checked'),'on')set(hObject, 'Checked', 'off');set(hb,'State', 'off');elseset(hObject, 'Checked', 'on');set(hb,'State', 'on');end。

MATLABGUI函数教程

MATLABGUI函数教程

MATLABGUI函数教程MATLAB(Matrix Laboratory)是一种高性能的数值计算和科学计算软件,广泛应用于工程、科学和金融领域。

除了使用MATLAB编写脚本文件进行计算外,MATLAB还提供了GUI(Graphical User Interface,图形用户界面)函数,使用户可以通过可视化界面进行操作和交互。

要创建一个GUI界面,首先需要创建一个GUI主窗口。

可以使用`figure`函数创建一个新的窗口,并设置窗口的属性,如窗口名称、大小和位置等。

然后,可以向主窗口添加各种控件,如按钮、菜单和文本框,以及其他界面元素。

在MATLABGUI中,可以使用回调函数来响应用户的操作。

回调函数是一段MATLAB代码,当用户在界面上执行一些操作时,该代码将被执行。

可以通过将回调函数与控件的事件(如按钮点击)关联起来,从而实现对用户操作的反应。

在GUI中,可以使用回调函数来执行各种操作,包括数据处理、图形绘制和文件操作等。

例如,当用户点击按钮时,可以编写一个回调函数来读取输入数据、进行计算,并将结果显示在界面上。

在GUI中,还可以使用各种布局管理器来控制控件的位置和大小。

布局管理器可以自动调整控件的位置,以适应窗口大小的变化。

常见的布局管理器包括`uiflowcontainer`、`uilayoutgrid`和`uitabgroup`等。

除了使用GUI函数来创建界面之外,MATLAB还提供了一些可视化工具箱,如GUIDE(GUI Development Environment),可以通过可视化界面设计工具来创建GUI界面。

GUIDE提供了一个图形界面,可以轻松地添加控件、设置属性和编写回调函数。

总结起来,MATLAB的GUI函数提供了一种方便、灵活的方式来创建交互式界面。

通过使用GUI函数,用户可以通过可视化界面进行数据处理、图形绘制和其他各种操作。

使用GUI函数可以为MATLAB程序增加更好的用户体验,并提高程序的可用性和易用性。

matlab练习(创建GUI)

matlab练习(创建GUI)

matlab练习(创建GUI)matlab创建GUI⽅法1:使⽤GUIDE菜单式操作在matlab中输⼊guide,可以打开guide创建GUI的图形界⾯,按菜单操作即可注:matlab未来版本可能会取消掉这种⽅式⽅法2:编写代码创建GUI下⾯是⼀个简单的以代码⽅式创建GUI的例⼦,其中关键的⼀些点包括1. 创建⼀个figure object作为container2. 通过`uicontrol`创建container内的控件,通过`'Callback'`属性关联回调函数3. 回调函数参数⼀般是由两部分组成`(source,eventdata,handles)`,分别表⽰引起回调产⽣的控件的handle和(点击)事件的数据function simple_gui2% SIMPLE_GUI2 Select a data set from the pop-up menu, then% click one of the plot-type push buttons. Clicking the button% plots the selected data in the axes.% Create and then hide the UI as it is being constructed.f = figure('Visible','off','Position',[360,200,450,285]);% Construct the components.hsurf = uicontrol('Style','pushbutton','String','Surf',...'Position',[315,220,70,25],...'Callback',{@surfbutton_Callback});hmesh = uicontrol('Style','pushbutton',...'String','Mesh','Position',[315,180,70,25],...'Callback',@meshbutton_Callback);hcontour = uicontrol('Style','pushbutton',...'String','Contour','Position',[315,135,70,25],...'Callback',@contourbutton_Callback);htext = uicontrol('Style','text','String','Select Data',...'Position',[325,90,60,15]);hpopup = uicontrol('Style','popupmenu',...'String',{'Peaks','Membrane','Sinc'},...'Position',[300,50,100,25],...'Callback',@popup_menu_Callback);ha = axes('Units','pixels','Position',[50,60,200,185]);align([hsurf,hmesh,hcontour,htext,hpopup],'Center','None');% Initialize the UI.% Change units to normalized so components resize automatically.f.Units = 'normalized';ha.Units = 'normalized';hsurf.Units = 'normalized';hmesh.Units = 'normalized';hcontour.Units = 'normalized';htext.Units = 'normalized';hpopup.Units = 'normalized';% Generate the data to plot.peaks_data = peaks(35);membrane_data = membrane;[x,y] = meshgrid(-8:.5:8);r = sqrt(x.^2+y.^2) + eps;sinc_data = sin(r)./r;% Create a plot in the axes.current_data = peaks_data;surf(current_data);% Assign a name to appear in the window title. = 'Simple GUI';% Move the window to the center of the screen.movegui(f,'center')% Make the UI visible.f.Visible = 'on';% Pop-up menu callback. Read the pop-up menu Value property to% determine which item is currently displayed and make it the% current data. This callback automatically has access to% current_data because this function is nested at a lower level. function popup_menu_Callback(source,eventdata) % Determine the selected data set. str = source.String; val = source.Value; % Set current data to the selected data set. switch str{val}; case 'Peaks' % User selects Peaks. current_data = peaks_data; case 'Membrane' % User selects Membrane. current_data = membrane_data; case 'Sinc' % User selects Sinc. current_data = sinc_data; end end% Push button callbacks. Each callback plots current_data in the% specified plot type. function surfbutton_Callback(source,eventdata) % Display surf plot of the currently selected data. surf(current_data); end function meshbutton_Callback(source,eventdata) % Display mesh plot of the currently selected data. mesh(current_data); end function contourbutton_Callback(source,eventdata) % Display contour plot of the currently selected data. contour(current_data); endendGUI展⽰⽅法3:利⽤AppDesigner和⽅法⼀的Guide类似总结我们有三种不同⽅式在matlab中创建简单的GUI程序,其中⽐较推荐的是使⽤编程的⽅式。

MatlabGUI设计详细说明

MatlabGUI设计详细说明

MatlabGUI设计详细说明Matlab GUI设计⼩结1.pushbutton在function pushbutton1_Callback(hObject,eventdata,handles)下进⾏pushbutton功能设计,按下pushbutton后会执⾏回调函数callback中的程序,双击pushbutton弹出属性编辑对话框,在String中可以键⼊pushbutton的名字function pushbutton1_Callback(hObject,eventdata,handles)%功能程序代码guidata(hObject,handles);2.edit编辑框%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%get()set()num2str()str2num()open函数名%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% edit可以作为输⼊输出读⼊数据d=get(handles.edit1,’String’);这时读进来的是字符型数据,通过str2num可以转换成double型d=str2num(d);作为输出,通过set来设置,输出的应该是字符型,可以通过num2str把set(handles.edit1,’String’,num2str(d));matlab的系统函数如get(),set(),num2str(),str2num()可以通过在matlab命令⾏中键⼊open函数名来查看函数实现源代码3.static text静态⽂本框text只能作为输出,通过set(handles.text1,’String’,str)来设置text显⽰的内容,也可以在属性编辑对话框中String中直接键⼊。

4.popupmenu下拉菜单这是第⼀个⽐较复杂的对象。

在GUI编程可以直接在属性编辑对话框中String⼀项直接键⼊下拉菜单中的内容然后是如何读取下拉菜单中选中的内容通过Value可以获取下拉菜单中当前选中的是哪⼀个String,Val=get(handles.popupmenu1,’Value’)返回的是下拉菜单中选中的string对应的位置Popupmenu其实是⼀个字符串数组,Value返回的是当前选中的字符串在数组中的下标,下标是从1开始。

利用Matlab GUI实现磁测数据畸变点的交互式剔除

利用Matlab GUI实现磁测数据畸变点的交互式剔除

利用Matlab GUI实现磁测数据畸变点的交互式剔除周志杰;赵文举;赵荔【摘要】he high precision magnetic survey is liable to suffering many kinds of surface interference which cause data distortion; therefore , the distortion points must be rejected before processing. For the purpose of implementing interactive rejection of distortion points in magnetic data, the authors employed the functions of Matlab GUI, which are characterized by visualization, drawing and mouse case. In practical application, this method enhances the efficiency of rejecting distortion points in magnetic data and preserves most information of normal data points.%进行高精度磁测会受到很多地表干扰,造成采集数据畸变,因此必须在各种处理方法运用之前剔除掉.利用Matlab GUI的可视化、绘图及鼠标事件功能,实现了交互式地剔除地表磁测数据中畸变点的方法.实践表明,这种方法不仅提高了畸变点的剔除效率,还可以最大程度地保留正常数据点的信息.【期刊名称】《物探与化探》【年(卷),期】2012(036)002【总页数】5页(P302-306)【关键词】磁测数据;Matlab GUI;畸变点剔除;人机交互;可视化【作者】周志杰;赵文举;赵荔【作者单位】甘肃省地矿局第二地质矿产勘查院,甘肃兰州730020;中国石油东方地球物理勘探有限责任公司,河北涿州072751;中国石油东方地球物理勘探有限责任公司,河北涿州072751【正文语种】中文【中图分类】P631.2高精度磁测数据野外采集过程中,由于其方法本身特点,容易受地表人文环境的干扰,这些干扰有时候不可避免,这就造成采集数据畸变,形成一些单点和区域性的畸变。

MatlabGUI菜单设计

MatlabGUI菜单设计
建立自定义的用户菜单的函数为uimenu,格式为: Hm=uimenu(Hp,属性名1,属性值1,属性 名2,属性值2,…) 功能:创建句柄值为Hm的自定义的用户菜单。其中Hp为 其父对象的句柄,属性名和属性值构成属性二元对,定义 用户菜单的属性。
因其调用方法不同,该函数可以用于建立一级菜 单项和子菜单项。 建立一级菜单项的函数调用格式为: 一级菜单项句柄=uimenu(图形窗口句柄,属性 名1,属性值1,属性名2,属性值2,…)
③ UserData属性 UserData属性的取值是一个矩阵,缺省值为空矩阵, 用户可以在这个属性中保存与该菜单对象相关的重要数 据或信息,借此可以达到传递数据或信息的目的。可以 用set和get函数访问该属性。 回调属性(callback)和菜单名(label)
【*例 11.3.3.1-1】本例的目标是:在图形窗上自制一个名为【Test】的“顶层菜 单项”;当用鼠标点动该菜单项时,将产生一个带分格的封闭坐标轴。通过本 例说明:(A)回调属性的运作机理;(B)用户顶层菜单项的制作(C) uimenu 属性的设置方法;(D)复杂字符串的构成方法和注意事项。 (1)在 MATLAB 指令窗中运行以下程序可产生带分格的封闭坐标轴(如下图) grid on,set(gca,'box','on')
(2)在 MATLAB 指令窗中用以下
eval 指令可产生与图 11.3.3.1-1 相同 的界面
eval('grid on,set(gca,''box'',''on'')') (3)产生题目要求的界面的 uimenu 的书写格式为:直接连续表 示法: uimenu('Label','Test','Callback','grid on,set(gca,''box'',''on''),')

MATLAB讲稿 图形用户界面设计(GUI)

MATLAB讲稿 图形用户界面设计(GUI)


使用属性查看器(Using Property Inspector) 布置控件; 定义文本框的属性; 定义坐标轴的属性; 定义按钮的属性; 定义复选框。
4. 菜单编辑器(Menu Editor) 利用菜单编辑器,可以创建、设置、修改下拉式菜单和 快捷菜单。选择 Tools 菜单下的 Menu Editor...子菜单,即 可打开菜单编辑器。
3. 用属性查看器设置控件属性 利用对象属性查看器,可以查看每个对象的属性值,也 可以修改、设置对象的属性值。 ① 打开属性查看器(Opening Property Inspector)
对象属性查看器的打开方式有四种: 从GUI设计窗口工具栏上选 择Property Inspector命令按钮; 选择View菜单下的Property Inspector菜单项; 在命令窗口中输入inspect; 在控件对象上单击鼠标右 键,选择弹出菜单的 Property Inspector菜单项。
菜单编辑器左上角的第四个与第五个按钮用于对选中的 菜单进行左移与右移,第六与第七个按钮用于对选中的菜单 进行上移与下移,最右边的按钮用于删除选中的菜单。
5. 对象浏览器(Object Browsers) 利用对象浏览器,可以查看当前设计阶段的各个句柄图 形对象。可以在对象浏览器中选中一个或多个控件来打开该 控件的属性编辑器。 对象浏览器的打开方式有: ① 从GUI设计窗口的工具栏上选择Object Browser命令按 钮; ② 选择View菜单下的Object Browser子菜单; ③ 在设计区域单击鼠标右键, 选择弹出菜单的 Object Browser。
2. 位置调整工具(Alignment tool) 利用位置调整工具,可以对GUI对象设计区内的多个 对象的位置进行调整。 位置调整工具的打开方式有两种: ① 从GUI设计窗口的工具栏上选择Align Objects命令按钮; ② 选择Tools菜单下的Align Objects...菜 单项,就可以打开对象位置调整器。 对象位置调整器中的第一栏是垂直方向的位置调整, 第二栏是水平方向的位置调整。 在选中多个对象后,可以方便的通过对象位置调整器 调整对象间的对齐方式和距离。

MATLAB的GUI编程方法

MATLAB的GUI编程方法

MATLAB的GUI编程方法一、引言在组合导航系统综合设计中,我主要负责应用MA TLAB对纯捷联惯导、捷联/GPS位置组合、速度组合、位置-速度组合等模式下的误差曲线进行绘制和比较。

在此过程中,我了解了导航解算的一般流程。

二、内容介绍1、MA TLAB简介MA TLAB最初是专门用于矩阵数值计算的软件,经过多年的发展完善,现在已经成为流行的科学计算与工程计算软件工具之一。

MA TLAB具备以下特点:1)程序环境高级并且容易掌握。

具有与其他语言编写的程序相结合和输入输出格式化数据的能力;2)程序限制不严格,自由度大。

拥有大量事先定义的数学函数,并且有很强大的用户自定义函数的能力;3)图形功能强大。

数据的可视化实现非常容易,可以轻松绘制各类二维、三维图形。

并且MA TLAB拥有较强的图形用户界面(GUI)的编辑能力。

2、MA TLAB的一般编程方法MA TLAB语言是由C语言编写的,因此它的语法与C语言有很大的相似之处。

MA TLAB编写的程序文件成为M文件,分为脚本文件和函数文件两种。

脚本文件是一个独立的程序文件。

而函数文件则需要输入输出参数,拥有独立的工作区和变量,整体相当于一个函数,供其他程序文件调用。

下面简单的介绍M文件的主要编程格式:1)如果是函数文件,则需要在文件的第一行定义函数:function[out1,out2,out3…]=FunName(in1,in2,in3…)顾名思义,中括号中的变量为输出参数,圆括号中的为输入参数;2)‘%’后的字符串为注释内容;3)函数体部分跟C语言较为类似,拥有各种结构化的控制语句(如for循环、while循环、switch语句和if语句等),允许函数嵌套和递归;4)M文件中可以使用匿名函数,用@返回函数句柄,这样就不用为每个函数建立一个函数文件了;5)可以定义私有函数,只能由父M文件能调用它。

实现方法是,在父M文件的目录里建立private文件夹,将私有函数放入该文件夹中。

MATLAB中的GUI程序设计

MATLAB中的GUI程序设计

第七章MATLAB 的图形用户界面(GUI)程序设计Chapter 8: Design of MATLAB of GUIprogram图形用户界面GUI(Graphical User Interfaces)是一种用户和计算机进行信息交流的工具和方法,由各种图形对象组成,在这种用户界面下,用户的命令和对程序的控制是通过鼠标等输入设备“选择” 各种图形对象来实现的。

软件开发者只需在由软件开发工具自动生成的程序代码中添加自己的运算或控制代码,就可以完成应用程序的设计。

目前90% 以上的应用程序和软件都是在GUI 下运行的。

MATLAB 有两种GUI 用户界面控件的创建方式,基于命令行的编程方式制作和基于MATLAB 提供的图形用户界面开发环境GUIDE 中的图形用户界面开发工具的GUI 创建方式制作。

这里主要介绍基于GUIDE 的创建方式。

MATLAB 的GUI的基本图形对象分为控件对象uicontrol和用户界面菜单对象uimenu(包括固定菜单和现场菜单),简称控件和菜单。

一. 控件对象及属性(Object and its attributes of controller))1.GUI 控件对象类型(The mode of controller object)控件对象是事件响应的图形界面对象。

当某一事件发生时,应用程序会做出响应并执行某些预定的功能子程序( Callback) .常用的基本控件:(1)按钮(Push Buttons:) 执行某种预定的单功能或操作;(2)双位开关按钮(Toggle Button:产生一个动作并指示一个二进制状态(开或关) ,当鼠标点击它时按钮将下陷,并执行callback (回调函数)中指定的内容,再次点击,按钮复原,并再次执行callback 中的内容;(3)单选框(Radio Button):单个的单选框用来在两种状态之间切换,多个单选框组成一个单选框组时,用户只能在一组状态中选择单一的状态,或称为单选项;(4)复选框(Check Boxes)单个的复选框用来在两种状态之间切换,多个复选框组成一个复选框组时,可使用户在一组状态中作组合式的选择,或称为多选项;(5)文本编辑器(Editable Texts):用来使用键盘输入字符串的值,可以对编辑框中的内容进行编辑、删除和替换等操作;(6)静态文本框(Static Texts)仅仅用于显示单行的说明文字;(7)滚动条(Slider):可输入指定范围的数量值;( 8)控件边框(Frames) 在图形窗口圈出一块区域;(9)列表框(List Boxes:在其中定义一系列可供选择的字符串;( 10)弹出式菜单(Popup Menus) 让用户从一列菜单项中选择一项作为参数输入;( 11)坐标轴(Axes) 用于显示图形和图象2.控件对象的描述(Description of controller object)MATLAB 中的控件大致可分为两种,一种为动作控件,鼠标点击这些控件时会产生相应的响应。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Matlab GUI Tutorial - Pop-up Menu29 Oct 2007 Quan Quach137 comments 20,912 views IntroductionIn this Matlab GUI tutorial, you will learn how to create and use thePop-up Menu component. Pop-up menus are used as a control forchoosing between a set of options. When the user clicks on the Pop-up menu, the menu expands, revealing a set of choices that the user can pick. A common use for Pop-up menus is a font size selector (shown below).This tutorial is written for those with little or no experience creating a Matlab GUI (Graphical User Interface). If you‟re new to creating GUIs in Matlab, you should visit this tutorial first. Basic knowledge of Matlab is not required, but recommended.Matlab version 2007a is used in writing this tutorial. Both earlier versions and new versions should be compatible as well (as long as it isan‟t too outdated). Let‟s get started!Create the Visual Aspect of the GUI1.First, open up Matlab. Go to the command window and type in guide.2.You should see the following screen appear. Choose the first option BlankGUI (Default).3.Click on and add a Static Text component to the GUI figure. Next, click onand add a Pop-up Menu component onto the GUI figure.4.Double click the Static Text component to bring up the Property Inspector.Change the String property to Testing!!!, and change the Tag property totesting_staticText as shown in the figure below:You can also modify the BackgroundColor property if you desire.5.Next, let‟s modify the properties of the Pop-up Menu component. First, clickon the icon on the String property line as shown below. This allows you to edit thedescription for each option in the Pop-Up Menu.After clicking on the icon, you should now see the following window. Fill in the window as shown below:In addition, I set the Tag property to popupmenu1, which is the default name. You might want to make sure that its named properly before you move on.6.Here‟s what your figure should look like after you add the components andmodify them.7.At this point, you also might want to add some Static Text components toadd some description tags to the GUI. You can modify their text by double clicking on the component and changing the String property. It‟s not required, but I highly recommend it.8.Save your GUI wherever you please with your desired filename.Writing the Code for the GUIMatlab automatically generates an .m file to go along with the figure that you just put together. The .m file is where we attach the appropriate code to the callback of each component. For the purposes of this tutorial, we are primarily concerned only with the callback functions. You don‟t have to worry about any of the other function types.1.Open up the .m file that was automatically generated when you saved yourGUI. In the Matlab editor, click on the icon, which will bring up a list of the functions within the .m file. Select popupmenu1_Callback.Add the following code to the function:%gets the selected optionswitch get(handles.popupmenu1,'Value')case1set(handles.testing_staticText,'FontSize',8);case2set(handles.testing_staticText,'FontSize',10);case3set(handles.testing_staticText,'FontSize',12);case4set(handles.testing_staticText,'FontSize',14);case5set(handles.testing_staticText,'FontSize',16);otherwiseend2.Lets quickly go over the code now. The following line of code gets the optionthat the user selected. Remember that in the visual layout of the GUI, wedesignated five different font sizes for the Pop-up Menu component, giving us five different options for the Pop-up Menu. So for example, if the user selected a font size of 8 (which was the first option in the Pop-up Menu), then the following line of code would return a value of 1. If the user selected a font size of 10, then the value returned would be 2, and so on.get(handles.popupmenu1,'Value')Depending on the option selected, the font of the Static Text component will be adjusted using the following line of code for each case statement:%where ## is the appropiate fontsize valueset(handles.testing_staticText,'FontSize',##);3.Save your m-file!Run and Test the GUINow that we‟ve completed both the visual and code aspects of the GUI, its time to run the GUI to make sure it works.1.From the m-file editor, you can click on the icon to save and run the GUI.Alternatively, from the GUIDE editor, you can click on the to launch the GUI. The following GUI should appear once you click the icon:2.Go ahead and try selecting different font sizes. If everything was donecorrectly, you should see the font size of the sample text change accordingly.3.And that‟s it. Those are the basics of using a Pop-up Menu component. Youcan explore the other options that the slider has to offer through the Property Inspector.This is the end of the tutorial.Source files can be downloaded here.Hello Bode,Thanks for catching the error. It‟s supposed to be popupmenu1_Callback! I have edited the page to reflect this.QuanThanks for the tutorial about pop up menu, but I want to ask you one question, how to show the a set of options in pop up menu from one field in table ( database ) , example : I use Ms access.ThankyouHi there,How would i go about changing the actual text for each font selected? i.e. when font 8 is selected from the drop down, the static text box will say “font 8 is called fred”, when font 10 is selected, “font 10 is called bill” etc etcThanksFroggy,You would change the string property to have it reflect what you want it to say.See step five of this tutorial. Instead of putting in numbers, put in what you want the menu to say.This is not my question Quan, I mean the drop down menu stays the same but the static box changes text depeding on what font you select, so when I choose a different font you will get different text or words unique to that font such as font 8 displays fred in the static box, font 10 displays bill in the static box, font 12 displays roger in the static box. However, if you simply change the string properties of the static box (so in this case you have five different texts for each of the five fonts), then how can you link them to the drop down menu?Try this:%gets the selected optionswitch get(handles.popupmenu1,'Value')case1set(handles.testing_staticText,'FontSize',8);set(handles.testing_staticText,'String','fred');case2set(handles.testing_staticText,'FontSize',10);set(handles.testing_staticText,'String','bill');case3set(handles.testing_staticText,'FontSize',12);set(handles.testing_staticText,'String','roger');case4set(handles.testing_staticText,'FontSize',14);case5set(handles.testing_staticText,'FontSize',16);otherwiseend11.on 15 Mar 2008 at 5:20 am 11AdnanHey there,If i have values in the pop-up menu, how do i save whatever the user selects in a variable that will be used to create a graph when i click on a push button in my GUI. Do you have any examples that relates to that?TQHy Quan and Daniel,What if I want to plot different value in the same axis according to the pop-up menu?I already tried to use your code and using plot(_,_) instead of set(), but nothing changed.Thank you for your help…I have a question. Can matlab do such a thing like - when you enter a number to “edit text” component, let us say number 10, then it appears 10 new edit boxes, and then you can do lots of stuff with those newly appeared edit boxes? If there is a tutorial on that, i would like to find it.Hi mini,that is possible but requires that you use lines of codes to create the GUI components. It‟s a little bit more complicated, and I‟m sorry to inform you that we haven‟t yet covered that here at blinkdagger. I recall Doug over at mathworks covered that issue, you should give it a look. You might have to do some browsing into his older posts.QuanHi there Quan. I got one question for you.If I got a pop up menu that contains 2 menu, how do I send those string value to another function. For example:function filter_popup_Callback(hObject, eventdata, handles)switch get(handles.filter_popup,‟String‟)case …Unsharp‟set(handles.linear_pushbutton,‟String‟,'unsharp‟);case …Average‟set(handles.linear_pushbutton,‟String‟,'average‟);endfunction linear_pushbutton_Callback(hObject, eventdata, handles)I = getimage(handles.axesBefore);h = fspecial(‟sobel‟);I2 = imfilter(I,h);Let‟s say I‟ve choosen Unsharp menu from the pop-up, how do I replace the ‟sobel‟ in the linear_p ushbutton to …unsharp‟?Thank youDanny,The following should workfunction linear_pushbutton_Callback(hObject, eventdata, handles)%get the stringbuttonText = get(handles.filter_popup,'String');I = getimage(handles.axesBefore);h = fspecial(buttonText);I2 = imfilter(I,h);19.on 04 Apr 2008 at 11:40 pm 19DannyWell Quan, thank you for that. After I‟ve done the modification, MATLAB provides me with this error… Can you help me out with this? Thank you so much. This is the error that comes out at the MATLAB when the GUI is being run.??? Error using ==>ImageEnhancement(‟linear_pushbutton_Callback‟,gcbo,[],guidata(gcbo)) Function FSPECIAL expected its first input, TYPE,to be one of these types:charInstead its type was cell.Oh yea… they gave out this error too… Its from the pop up menu??? Error using ==>ImageEnhancement(‟filter_popup_Callback‟,gcbo,[],guidata(gcbo))SWITCH expression must be a scalar or string constant.??? Error while evaluating uicontrol CallbackHey danny,you‟re right, i gave you some faulty code. I didn‟t have matlab on the pc so I couldn‟t double check my answer. I‟ll get back to you on this one.Quanthis code should work. i tested it on matlab!sorry for the delayfunction linear_pushbutton_Callback(hObject, eventdata, handles)%get the value of the current selectionchoiceValue = get(handles.filter_popup,'Value');%get the string data from the popupmenu%notice the string data is in a cell formatstringData = get(handles.filter_popup,'String');%notice the curly brackets used herebuttonText = stringData{choiceValue};I = getimage(handles.axesBefore);h = fspecial(buttonText);I2 = imfilter(I,h);24.on 07 Apr 2008 at 6:01 am 24DannyHiMy problem to call popup menu is:I have created in my gui a pop-up window “Direction” with3 menues (AP,RL and FH) that must shows the direction ofmedical image in 3 direction. When the user chooses it. Itried to call the function. This pop up menu is not active.It shows only the first or default image. What can I do tosolve this problem? and I tried to plot the image in case of popup as showen. But I get only deufalt image. my popup button has no function================================================== function plot_popupmenu_Callback(hObject, eventdata, handles)% hObject handle to plot_popupmenu (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,‟String‟) returns plot_popupmenu contents as cell array% contents{get(hObject,‟Value‟)} returns selected item from plot_popupmenu%################################################# #########################%get the value of the current Pop-up menu selection%plotType =1, if AP option is chosen%plotType =2, if FH option is chosen%plotType =3, if RL option is chosenvelocityDirection = get(handles.plot_popupmenu,‟Value‟)%get(hObject,‟Value‟);%val = get(hObject,‟Value‟);str = get(hObject, …String‟);switch str{velocityDirection};case …AP‟handles.current_data = handles.phaseImageAP;case …FH‟handles.current_data = handles.phaseImageFH;case …RL‟handles.current_data = handles.phaseImageRL; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%get(handles.plot_popupmenu,‟Value‟)axes(handles.axes2);%gives focus to second axesif velocityDirection ==1imshow(handles.phaseImageAP,[]);colormap(gray);zoom on;else if velocityDirection == 2imshow(handles.phaseImageFH,[]);colormap(gray);zoom on;else ifimshow(handles.phaseImageAP,[]);colormap(gray);zoom on;handles.current_data = handles.phaseImageAP;axes(handles.axes2);%gives focus to second axesimshow(handles.current_data,[]);colormap(gray);zoom on;endguidata(hObject,handles)hipleas can you help me to set the data in the pop menu by a vector because all tutorial shown that the dat is defined manualy and can not be edit or set automatically.Hello,I need help with something. I have a pop-up menu in my gui and I have added several values that can be selected from the user. I want to be able to take the value selected as a number(eg a 2) and be able to use this in another m-file (my gui‟s engine). Any ideas?This tutorial helps me somewhat, but I there is one problem I‟m having. Is there an easy way to add new items to the popup menu after the GUI is running.For example, The GUI starts out with Zero items in the popup menu. The user has the ability to type text in a text box then hit a button to add that text to the popup menu list.Thanks in advance.Hi, I have essentially the same question as Sam above: how do we set up the switch cases for a dynamically generated pop-up list, after the GUI is running?Specifically in my GUI, the user selects a file, which has a variable number of signal recordings, whose names are copied into the pop-up menu; how can I perform actions on those different signals by selecting them from the pop-up menu?Thanks in advance!Hi Quan,I am writing a program to predict deflections of cantilevered and simply supported beams, under either single point, or uniformly distributed loads (UDL).I wish to use a pop-up menu to give the user a choice of material of the beam (including an option for the user to enter their own value (young‟s modulus)), and another to choose the cross-section of the beam.What i would like to know is how would you put in an equation so that if the user selected, for example a rectangular cross section, the program would know to sub values that the user entered via edittext boxes, into that particular equation, and then take the resulting value and place it in a final equation that would calulate the deflection of the beam.Hi every body.I am Vietnameses. I am learning processing image with Matlab. I need help with something:I had a Axes to display image with name is axes_image. And now , I want setup apop-up menu with string is colors pink, gray, hsv to processing this image(image in axes_image). I want use function pink, gray, hsv of Matlab to process. But I can‟t. Please help me. I write this code but it don‟t run.Val = get(handles.popupmenu1, …value‟);Str = get(handl es.popupmenu1,‟string‟);switch str(val)case …gray‟handles.current_data = handles.x;case …hsv‟handles.current_data = handles.x;case …pink‟handles.current_data = handles.x;get(handles.popupmenu1,‟value‟);axes(handles.axes2);if Val ==1imshow(handles.x,[]);colormap(gray);else if Val == 2imshow(handles.x,[]);colormap(hsv);else Val == 3;imshow(handles.x,[]) ;colormap(pink);endUsing iscell and ischar in Matlab 2007b, my PopUpMenuCallback is returning a character array instead of a cell array when doing get(hObject,‟String‟).Instead of using a cell array as you indicated in your code sample from 06 Apr 2008 at 10:40 pm 23 (using the curly brackets), I had to do the following:function PopUpMenu_Callback(hObject, eventdata, handles)val = get(hObject,‟Value‟)string_list = get(hObject,‟String‟)selected_string = string_list(val,1:end)Has there been a change in Matlab or is there something screwy with my system?Thank youI can‟t say for sure, but if there is only one string in the string list, then the data type is a “string”. If there are multiple strings in the pop up menu then it would be a “cell”.I don‟t believe anything has changed between versions, so I will have to check.QuanBetween your reply and further reading, it finally dawned on me that depending upon how the strings are set in the popup menu dictates the method used for reading them. see the two example belowusing a string vectorfunction popUpMenu_Callback(hObject, eventdata, handles)set(hObject,‟String‟,['one|two|three'])val = get(hObject,‟Value‟)string_list = get(hObject,‟String‟)selected_string = string_list(val,1:end)using a cell array of stringsfunction popUpMenu_Callback(hObject, eventdata, handles)set(hObject,‟String‟,{‟one‟ …two‟ …three‟})val = get(hObject,‟Value‟)string_list = get(hObject,‟String‟)selected_string = string_list{val}hello,I found your tutorials very helpful, but i still have a question:let‟s say i have 2 popup menus. How should i proceed if the options in the second menu depend on the choice in the first menu?ex: menu1 = 1, 2 or 3and menu2 = 11, 12 or13 if menu1 = 1menu2 = 21, 22, 23 or 24 if menu1 = 2and so on ?Thanks in advance.L.Lauren,Assuming you have two popupmenus named popupmenu1 and popupmenu2:%notice the curly brackets here%myinput1 is a cell!myInput1 = {'Option1', 'Option2', 'Option3'};myInput2 = {'Apple', 'Orange', 'Pear'};%%% and so on%inside the first popupmenu fucntionswitch get(handles.popupmenu1,'Value')case1%set the parameters of the popupmenu2 if the first option% in popupmenu1 is chosenset(handles.popupmenu2,'String',myInput1);case2set(handles.popupmenu2,'String',myInput2);case3set(handles.popupmenu2,'String',myInput3);case4set(handles.popupmenu2,'String',myInput4);case5set(handles.popupmenu2,'String',myInput5);otherwiseend43.on 07 Aug 2008 at 3:04 am 43LaurenhelloQuanI also found your tutorials very helpful, but i still have a question:if my popup contain string for examplec:\fdfd\hjhjhc:\fd\hgd:\ah\ghand i want to do some processing in other function and add new item to popupmenu examplee:\af\ajhow can i do thatthank youahmedahmed,You can try the following:%first get the string inside the current popup menumyCell = get(handles.popupmenu,'String');%next, add a new item to the cell%notice the curly brackets here!myCell{end+1} = 'My new item';%next, update the popupmenuset(handles.popupmen,'String',myCell)'Hope that helpsQuanOh thank you Quanyes it work goodthank you v.much for your helpahmedHello Quan Quach,I would like to ask how would you write a code with a popup menu in which when i select an option from the menu, a desired image would be displayed on the GUI?For example, i‟m doing a project on Plantar images of a foot, if i would to choose region 1 from the popup menu, how would i display an image(found on myhard-drive) on the GUI?Would really appreciate your help. Thanks.switch get(handles.popupmenu2,‟Value‟)case 1set(handles.testing_staticText1,‟FontSize‟,10);set(handles.testing_staticText1,‟String‟,'Region 1′);case 2set(handles.testing_staticText1,‟FontSize‟,10);set(handles.testing_staticText1,‟String‟,'Region 2′);case 3set(handles.testing_staticText1,‟FontSize‟,10);set(handles.testing_staticText1,‟String‟,'Region 5′);case 4set(handles.testing_staticText1,‟FontSize‟,10);set(handles.testing_staticText1,‟String‟,'Region 6′);case 5set(handles.testing_staticTex t1,‟FontSize‟,10);set(handles.testing_staticText1,‟String‟,'Region 7′);otherwiseendnicksterrSay I decide to place a set of edit text boxes. I want the user to put numeric values in each box. Then I want to be able to define a matrix from the numbers the user put in the edit text boxes.example: edit text box 1 tag is changed to x1, text box 2 to x2, and so on.I want to be able to create a matrix such that x = [x1 x2 x3....]Any advice?50.on 03 Feb 2009 at 1:55 pm 50james51.switch get(handles.popupmenu1,'Value')52.case153. x1=get(handles.x1,'String')54. x2=get(handles.x2,'String')55. x3=get(handles.x3,'String')56. x4=get(handles.x4,'String')57. x5=get(handles.x5,'String')58. x6=get(handles.x6,'String')59.60. x=[x1 x2 x3 x4 x5 x6]61.62. w1=get(handles.w1,'String')63. w2=get(handles.w2,'String')64. w3=get(handles.w3,'String')65. w4=get(handles.w4,'String')66. w5=get(handles.w5,'String')69.on 03 Feb 2009 at 2:19 pm 51james70.switch get(handles.popupmenu1,'Value')71.case172. x1=get(handles.x1,'String')73. x2=get(handles.x2,'String')74. x3=get(handles.x3,'String')75. x4=get(handles.x4,'String')76. x5=get(handles.x5,'String')77. x6=get(handles.x6,'String')78.79. x=[x1, x2, x3, x4, x5, x6]'80.81. w1=get(handles.w1,'String')82. w2=get(handles.w2,'String')83. w3=get(handles.w3,'String')84. w4=get(handles.w4,'String')85. w5=get(handles.w5,'String')86. w6=get(handles.w6,'String')87.88. w=[w1, w2, w3, w4, w5, w6]'89.net=w'*xso…can someone explain to me why this is returningnet =14654the matrices should be a 1×6 times a 6×1…resulting in a 1×1…somethings wrong…please help!hi i want to add a new pop-pup string to an pop-pup but this code erase all the other item and create a new itemset(handles.mypoppup,‟string‟,'new item‟)please can you people help me to add it not to erase and then createthanksHi..I want creat a popup menu dat allows me to run different simulink files files on different selection…..that is if i select option “first order” in the popup me nu then it should run simulink file named firstorder.mdl and if i select “second order” in popup menu then it should run simulink file named secorder.mdl….. How can i do dat??? Please help…. Thanks in advance..Hi.. i want to create a dynamic pop-up menu and for each item in menu i have to get a value. how should i do that.Problem : Like in a liquid system you …n‟ no. of components . so pop up menu has elements Component 1, Component 2… and so on uptil Component …n‟. For each component i have to get its respective composition in mole fraction. Also …n‟ is given at runtime. How can i do this.Akshayy,Good question. You‟ll have to modify the pop-up menu widget within the code to make it work. Once you know what N is, you can use the following code to modify the pop up menu. I don‟t have MATLAB handy, so I can‟t confirm if this exact code will work, but hopefully you get the idea!%create a cell that has n rowsmyCell = cell(n,1);for x=1:length(myCell)myCell{x} = ['Component 'num2str(x)];end%next, update the popupmenuset(handles.popupmenu,'String',myCell)'QuanHi QuanThnx a lot. It really helped. I was trying strcat but it was not working.I also have to get compositions for the n-components and 4 that i don‟t want to make …n‟ edit boxes i want 2 control from 1 only. i tried set function 2 reset edit box value to NULL and the ask user to enter but it is not working. Can u plz help.Hithnx again. but i tried on my own and did it. instead of using switch i just passes around using ->val=get(hObject,‟Value‟);set(handles.pb2,‟Visible‟,'on‟);set(handles.pb3,‟Visible‟,'on‟);str=num2str((val));set(handles.text2,‟Visible‟,'off‟);set(handles.text2,‟String‟,str);guidata(hObject,handles);Hi Quan,I found your website very useful in all matters concering matlab.I‟m relatively new to gui‟s in matlab. Just trying to write callbacks for my popupmenu. At the moment this is what i have:function popupmenu1_Callback(hObject, eventdata, handles)% hObject handle to popupmenu1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,‟String‟) returns popupmenu1 contents as cell array% contents{get(h Object,‟Value‟)} returns selected item from popupmenu1val = get(hObject,‟Value‟);switch valcase 1set(handles.popupmenu1,‟Value‟,Frequency (Hz))case 2set(handles.popupmenu1,‟Value‟,4)for i= 1:5imshow(C);pause(0.5);imshow(I);pause(0.5);endcase 3set(handles.popupmenu1,‟Value‟,8)case 4set(handles.popupmenu1,‟Value‟,16)end(2) when i select the value 4 it should enter the for loop,i have already added the strings to the property inspector string tag. and i have added values as well. i.e value 1.0, 2.0, 3.0, 4.0.Does anyone have any ideasCheersKartikHi,Thank you very much for the tutorial.I want to ask that whether it is possible to use popup menu for inputing data file? If so, how shall I start the programme?Regardshi………thank you very much for the tutoriali want to design a guide for automatic control system.could you help me about command “callback”.and using in m-file.if you know vietnamese,i can say with you by vietnamese.cheersthangYour website is very helpful for someone like me who is absolutely clueless with programming. Thank you very much!!I have a quick question regarding the popup menu. I am making a program to calculate the metabolism rate of human. I want the users to choose the gender from the popup (male or female) and calculate the rate accordingly. There will be different coefficients depending on the gender (ex: 5 for male, 3 for female). How do I develop the MATLAB code to link the coefficients so it will automatically calculate the rate?Bests,DiannaDianna,I‟m sure Quan loves hearing those kind words. You should be able to follow the steps from this tutorial to do that, but I‟ll show you where it differs:In step 4 of the first page of this tutorial, inst ead of filling in the …String‟ box (from the inspector bar) with numbers, you would put …Male‟ and …Female‟ on separate lines. I like having a blank line at the top (3 lines total) so the …default‟ would show a blank, instead of …Male‟ in my example.The 2nd major difference would be in the callback function for the popup menu (step 1 on 2nd page of tutorial)Each …case‟ represents the different lines from the …String‟ box you just createdswitch get(handles.popupmenu1,'Value')case1return% if your first line is blank, this breaks out of the callback.case2%Malehandles.Coeff=5; %saving the coeffecient to handles.Coeff lets you access % this value anywhere else in your GUI since handles is an%input to EVERY function in the GUIcase3%Femalehandles.Coeff=3;otherwiseendguidata(hObject, handles);You can then calculate your value at the end of the callback, or you can associate the calculation in another function in your GUI.I hope that‟s clear,-ZaneThanks Zane!When I include the coefficients to the function, do I include (ex: from the tutorial for beginners) like this?a = get(handles.input1_editText,'String');b = get(handles.input2_editText,'String');c = get(handles.popupmenu1,'Value');% a and b are variables of Strings type, and need to be converted% to variables of Number type before they can be added together% c depends on the coefficienttotal = str2num(c)*str2num(a) + str2num(b);d = num2str(total);% need to convert the answer back into String type to display itset(handles.answer_staticText,'String',d);guidata(hObject, handles);It does not seem to work. Hope to hear from you soon.DiannaHello Dianna,Zane pretty much summed it up nicely in his response. If you are planning on keeping your metabolism coefficients constant, then you should just hard code it into the GUI m-file, as Zane did. If you want the user to be able to specify the coefficient, then you would use the edit text box, similar to the tutorial for beginners.Please take a closer look at what Zane wrote as did a pretty thorough job. Take a look below at the code I modified as well.。

相关文档
最新文档