MATLAB app designer rookie Advanced Learning (a)

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

Value - Value 
Items element | ItemsData elements

  Value that specifies  Items or  ItemsData elements of the array. By default, Value it is  Items the first element.

  Will be  Value designated as  Items an element, you can select the drop-down items that match the element. If  ItemsData non-empty,  Value it is set to be  ItemsData an element, but the drop-down list to select the associated item in the list.

Items - dropdown 
{ 'Option 1', 'Option 2', 'Option 3', 'Option 4'} ( default) | Cellular character vector array | string array | ...

  Dropdown, designated character vector cellular array, the array of strings or one-dimensional array classification. Allowing duplicate elements. Options pull-down component displays  Items as many as the number of elements in the array. If you specify this property as an array of classification, MATLAB® will use the values in the array, instead of the full set of categories.

ItemsData - Items associated with each attribute value of the element data 
empty array ([]) (default) | 1 × n array of values | 1 × n array Cellular

  And  Items the data element associated with each attribute value, designated as 1 × n 1 × n array of values or a cellular array. Allowing duplicate elements.

  For example, if you  Items set the value to the employee's name, you can  ItemsData set the value of the corresponding employee ID number. ItemsData App is not visible to the user value.

  If the  ItemsData value of  Items the number of array element values do not match, one of the following occurs:

  • If the  ItemsData value is blank,  Items all element values are presented to the user App.

  • If the  ItemsData number of elements in the value is greater than  Items value,  Items all element values are presented to the user App. MATLAB ignores the extra  ItemsData elements.

  • If a  ItemsData non-null value, but less than the number of elements in  Items value, only in  ItemsData having the corresponding elements in the value of  Items element values is presented to the user App.

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 属性具有下列两个可能的值:

  • 'on' - 允许其他回调中断对象的回调。中断发生在 MATLAB 处理队列的下一个位置,例如当存在 drawnowfigureuifiguregetframewaitfor 或 pause 命令时。

    • 如果运行中回调包含以上命令之一,则 MATLAB 将在该时刻停止执行回调并执行中断回调。当中断回调完成时,MATLAB 将恢复执行运行中回调。

    • 如果运行中回调不包含以上命令之一,则 MATLAB 执行完当前回调,不会出现任何中断;

  • 'off' - 阻止所有中断尝试。由中断回调所属的对象的 BusyAction 属性决定是放弃该中断回调还是将其放入队列中。

usyAction - 回调排队
'queue' (默认) | 'cancel'

回调排队,指定为 'queue' 或 'cancel'BusyAction 属性决定 MATLAB 如何处理中断回调的执行。有以下两种回调状态要考虑:

  • 运行中回调是当前正在执行的回调。

  • 中断回调是试图中断运行中回调的回调。

无论何时 MATLAB 调用回调,该回调都会试图中断运行中回调。运行中回调所属对象的 Interruptible 属性决定着是否允许中断。如果不允许中断,则中断回调所属对象的属性 BusyAction 将决定是放弃该回调还是将回调放入队列中。以下是 BusyAction 属性的可能值:

  • 'queue' - 将中断回调放入队列中,以便在运行中回调执行完毕后进行处理。

  • 'cancel' - 不执行中断回调。

HandleVisibility - 对象句柄的可见性
'on' (默认) | 'callback' | 'off'

 对象句柄的可见性,指定为 'on''callback' 或 'off'

  此属性控制对象在其父级的子级列表中的可见性。当对象未显示在其父级的子级列表中时,通过搜索对象层次结构或查询属性来获取对象的函数不会返回该对象。这些函数包括 getfindobjclf 和 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)

  

 

Guess you like

Origin www.cnblogs.com/Sonny-xby/p/12614903.html