A, App Designer to start
1. Open
(1) Open Home App Design Tool
appdesigner
(2) to open an existing file App
appdesigner(filename)
filename:
App file name or path, specified as a character string scalar or vector. You may include in the file name .mlapp
. You can only pass a file name to the appdesigner
function.
If you filename
appear in the search path of multiple folders, include the path to the file. The file specification must use the full path or relative path to the file, or the name of the file on the MATLAB path.
Example: appdesigner('app1.mlapp')
Example: appdesigner("app1")
Example: appdesigner("C:\Documents\Data\watertables.mlapp")
(3) the menu bar to open
New --App
2. Home
You can create a new blank in the Home App, or a new feature automatically adjusts the layout of the two-column or columns have three type App, you can:
-
App to view a list of recently used.
-
Explore featured examples to help get started.
-
Reference tutorials to learn the basics App design tools.
-
App design exploration tool tutorial focuses on new features.
Second, control
2.1 Common Components
2.1.1 The drop-down box
In addition to direct drag and drop, but here Oppression program to create and edit mode.
(1) automatically generates a drop-down box
The program automatically creates a drop-down component of the project has a default.
fig = uifigure; dd = uidropdown(fig);
(2) program to create a drop-down component specified items.
fig = uifigure; dd = uidropdown(fig,'Items',{'Red','Yellow','Blue','Green'},... 'Value','Blue');
(3) to create editable drop-down list
fig = uifigure; dd = uidropdown(fig,'Editable','on');
(4) property
Font and color (slightly)
Interactivity
Visible
Property to determine whether the drop-down component displayed on the screen. If the Visible
property is set 'off'
, the drop-down components are hidden but still accessible and you can specify its properties. App to make faster starts, all components of the set need not be present at startup Visible
property is set 'off'
.
Editable attribute value is , the user can not change the drop-down assembly App text, even Editable attribute value is true.'on',则下拉组件文本可更改;当
Enable
'off'
'on'
Enable property
-
If you set this property value
'on'
, the appearance of drop-down component will indicate App users can change the drop-down component values. -
If you set this property value
'off'
, the appearance of drop-down component grayed out. This indicates the App user can not change the appearance of the drop-down component values, and drop-down component does not trigger any callbacks.
tooltips 工具提示,指定为字符向量、字符向量元胞数组、字符串数组或一维分类数组。如果使用此属性,则在运行时当用户将指针悬停在组件上时,将显示消息。即使禁用组件,工具提示也会显示。要显示多行文本,请指定字符向量元胞数组或字符串数组。数组中的每个元素变为一行文本。如果将此属性指定为分类数组,MATLAB 将使用数组中的值,而不是完整的类别集。
回调属性
Interruptible - 回调中断 'on' (默认) | 'off'
回调中断,指定为 'on'
或 'off'
。Interruptible
属性确定是否可以中断运行中回调。
有以下两种回调状态要考虑:
-
运行中回调是当前正在执行的回调。
-
中断回调是试图中断运行中回调的回调。
每当 MATLAB 调用回调时,回调都会试图中断正在运行的回调(如果存在)。运行中回调所属对象的 Interruptible
属性决定着是否允许中断。Interruptible
属性具有下列两个可能的值:
usyAction - 回调排队 'queue' (默认) | 'cancel'
回调排队,指定为 'queue'
或 'cancel'
。BusyAction
属性决定 MATLAB 如何处理中断回调的执行。有以下两种回调状态要考虑:
-
运行中回调是当前正在执行的回调。
-
中断回调是试图中断运行中回调的回调。
无论何时 MATLAB 调用回调,该回调都会试图中断运行中回调。运行中回调所属对象的 Interruptible
属性决定着是否允许中断。如果不允许中断,则中断回调所属对象的属性 BusyAction
将决定是放弃该回调还是将回调放入队列中。以下是 BusyAction
属性的可能值:
-
'queue'
- 将中断回调放入队列中,以便在运行中回调执行完毕后进行处理。 -
'cancel'
- 不执行中断回调。
HandleVisibility - 对象句柄的可见性 'on' (默认) | 'callback' | 'off'
对象句柄的可见性,指定为 'on'
、'callback'
或 'off'
。
此属性控制对象在其父级的子级列表中的可见性。当对象未显示在其父级的子级列表中时,通过搜索对象层次结构或查询属性来获取对象的函数不会返回该对象。这些函数包括 get
、findobj
、clf
和 close
。对象即使在不可见时也有效。如果可以访问某个对象,则可以设置和获取其属性,并将其传递给针对对象进行运算的任意函数。
(6)示例
将以下代码保存到 MATLAB 路径中的 plotOptions.m
中。以下代码将创建一个窗口,其中包含一个绘图和一个下拉组件。当 App 用户更改下拉组件选择时,ValueChangedFcn
回调将改变绘图的颜色。
function plotOptions fig = uifigure; fig.Position(3:4) = [440 320]; ax = uiaxes('Parent',fig,... 'Position',[10 10 300 300]); x = linspace(-2*pi,2*pi); y = sin(x); p = plot(ax,x,y); p.Color = 'Blue'; dd = uidropdown(fig,... 'Position',[320 160 100 22],... 'Items',{'Red','Yellow','Blue','Green'},... 'Value','Blue',... 'ValueChangedFcn',@(dd,event) selection(dd,p)); end % Create ValueChangedFcn callback: function selection(dd,p) val = dd.Value; p.Color = val; end
创建一个下拉组件和一个信号灯。当 App 用户从下拉组件中选择选项时,信号灯的大小将改变。
请将以下代码保存到 MATLAB 路径中的 lampSize.m
中。以下代码将创建一个图窗窗口,其中包含一个下拉组件和一个信号灯。当 App 用户更改下拉组件选项时,ValueChangedFcn
回调将改变信号灯的大小。
function lampSize % Create figure and components fig = uifigure('Position',[100 100 300 275]); lmp = uilamp(fig,... 'Position',[100 30 20 20]); dd = uidropdown(fig,... 'Editable','on',... 'Position',[84 204 100 20],... 'Items',{'Size x 1','Size x 2','Size x 3','Size x 4'},... 'ItemsData',[1 2 3 4],... 'Value',1,... 'ValueChangedFcn',@(dd,event) optionSelected(dd,lmp)); end % Create ValueChangedFcn callback function optionSelected(dd,lmp) val = dd.Value; s = [20 20]; switch val case {1, 2, 3, 4} % User selected a defined option size = val * s; lmp.Position(3:4) = size; otherwise % User typed a value m = str2num(val); size = m * s; lmp.Position(3:4) = size; end end
(7)其他
下拉框控件的值 Value返回的是字符串,为了使返回值变为数值型,直接用于数值运算,可以采用语句:
value=str2double(app.XX.value)