uidropdown
Create drop-down component
描述
创建一个下拉的new figure window and returns thedd
= uidropdown落下
目的。MATLAB®calls theuifigure
创建图形的功能。
例子
创建下拉组件
使用默认项目创建一个下拉组件。
无花果= uifigure;dd = uidropdown(图);
单击下拉组件中的任何地方都会使其打开。
Set and Access Drop Down Properties
创建一个下拉组件并指定选项。
无花果= uifigure;dd = uidropdown(图,'项目',{'Red','黄色','蓝色的','绿色的'},,...'Value','蓝色的');
确定与所选选项关联的值。
瓦尔ue = dd.Value
值='蓝色'
默认情况下,项目数据
property is empty, so the drop-down component value corresponds to the element selected in the drop-down component.
将数据值与每个下拉组件项目相关联。
dd.itemsdata = [1 2 3 4];
确定与所选选项关联的值。
瓦尔ue = dd.Value
值= 3
请注意,当项目数据
属性值不是空的,下拉组件的值是项目数据
瓦尔ue that corresponds to the selected项目
值元素。
创建一个可编辑的下拉
无花果= uifigure;dd = uidropdown(图,“可编辑”,'on');
单击下拉组件中的任何位置(除弃箭)以外,插入光标,使用户能够在下拉式组件中键入文本。
Code Response to Drop Down Selection
创建一个图和下拉组件。当应用程序用户从下拉式组件中进行选择时,绘图会更改颜色。
Save the following code toplotoptions.m
在您的Matlab路径上。此代码创建一个包含图和下拉组件的窗口。当应用程序用户更改下拉组件选择时Valuechangedfcn
callback changes the plot color.
功能plotOptions fig = uifigure; fig.Position(3:4) = [440 320]; ax = uiaxes(“父母”,fig,...'位置',[10 10 300 300]); x = linspace(-2*pi,2*pi); y = sin(x); p = plot(ax,x,y); p.Color ='蓝色的';dd = uidropdown(图,...'位置',[320 160 100 22],,...'项目',{'Red','黄色','蓝色的','绿色的'},,...'Value','蓝色的',...'Valuechangedfcn',@(dd,event)选择(dd,p));end%创建ValueChangedFCN回调:功能selection(dd,p) val = dd.Value; p.Color = val;end
跑plotOptions
。选择绿色from the drop-down component to change the plot color to green.
对下拉组件条目或选择的代码响应
Create a drop-down component and a lamp. When the app user makes a selection from the drop-down component, the lamp size changes.
将以下代码保存到Lampsize.m
在您的Matlab路径上。This code creates a figure window containing a drop-down component and a lamp. When an app user changes the drop-down component selection, theValuechangedfcn
回调会更改灯的大小。
功能灯泡%创建图形和组件无花果= uifigure('位置',[100 100 300 275]);lmp = uilamp(图,...'位置',[100 30 20 20]); dd = uidropdown(fig,...“可编辑”,'on',...'位置',[84 204 100 20],...'项目',{'大小x 1','大小x 2','大小x 3','大小x 4'},,...'itempata',[1 2 3 4],...'Value',1,...'Valuechangedfcn',@(dd,event)optionsElected(dd,lmp));end%创建valuechangedfcn回调功能optionSelected(dd,lmp) val = dd.Value; s = [20 20];转变瓦尔案子{1,2,3,4}% User selected a defined option尺寸= val * s;lmp.position(3:4)=大小;否则%用户输入值m = str2num(val);尺寸= m * s;lmp.position(3:4)=大小;endend
跑灯泡
并从下拉组件中选择各种选项。
Type a value in the drop-down component and press进入。灯尺寸变化。(如果输入一个大价值,则可能必须调整数字大小才能看到灯。)
Input Arguments
父
—父容器
数字
object(默认)|控制板
object|标签
object|屁股群
object|网格布局
object
父容器, specified as a数字
使用uifigure
功能,或它的一个子容器之一:标签
,控制板
,屁股群
, 或者网格布局
。如果您不指定父容器,则MATLAB调用uifigure
功能to create a new数字
用作父容器的对象。
姓名-Value Arguments
将可选的参数对name1 = value1,...,namen = valuen
, 在哪里姓名
is the argument name and价值
是相应的值。名称值参数必须在其他参数之后出现,但是对的顺序并不重要。
在R2021a之前,请使用逗号分隔每个名称和值,并附上姓名
用引号。
例子:'项目',{''','Yellow','Blue'}
specifies the options presented in the drop-down component.
此处列出的属性是可用属性的子集。有关完整列表,请参阅下拉属性。
项目
—下拉物品
{'option 1','option 2','option 3','option 4'}
(默认)|字符向量的单元格数|string array|...
下拉项,指定为字符向量,字符串数组或1-D分类数组的单元格数组。允许重复元素。下拉组件显示的选项与此选项一样多项目
array. If you specify this property as a categorical array, MATLAB uses the values in the array, not the full set of categories.
例子:{'红色','Yellow','蓝色'}
例子:{'1','2','3'}
项目数据
—Data associated with each element of the项目
适当的价值
空数组([]
)(默认)|1-b-n数字阵列|1-n-n单元阵列
Data associated with each element of the项目
适当的价值, specified as a 1-by-n numeric array or a 1-by-n cell array. Duplicate elements are allowed.
例如,如果您设置项目
对员工姓名的价值,您可能会设置项目数据
对相应的员工ID号的价值。这项目数据
应用程序用户不可见值。
如果数组元素中的数量项目数据
价值和项目
瓦尔ue do not match, one of the following occurs:
当。。。的时候
项目数据
值是空的,然后是所有元素项目
值向应用程序用户提出。当。。。的时候
项目数据
价值比项目
价值,然后项目
值向应用程序用户提出。MATLABignores the extra项目数据
元素。当。。。的时候
项目数据
瓦尔ue is not empty, but has fewer elements than the项目
价值,唯一的要素项目
瓦尔ue presented to the app user are those that have a corresponding element in the项目数据
价值。
例子:{'One','Two','Three'}
例子:[10 20 30 40]
可编辑
—可编辑的下拉组件状态
'离开'
(默认)|开/关逻辑值
下拉组件的可编辑状态,指定为'离开'
或者'on'
,或数字或逻辑1
(真的
) or0
(false
)。一个值'on'
相当于真的
, 和'离开'
相当于false
。Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of typematlab.lang.onoffswitchstate
。
如果the使能够
属性值是'离开'
,那么应用程序用户也无法更改下拉组件文本,即使可编辑的属性值为'on'
。
Valuechangedfcn
—值更改了回调
''
(默认)|功能handle|单元阵列|角色向量
值更改了回调, specified as one of these values:
功能句柄。
A cell array in which the first element is a function handle. Subsequent elements in the cell array are the arguments to pass to the callback function.
A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.
当用户从下拉列表中选择其他选项时,此回调函数将执行。如果是价值
属性以编程方式更改。
此回调函数可以访问有关用户与下拉访问的交互的特定信息。Matlab将此信息传递到Valuechangeddata
object as the second argument to your callback function. In App Designer, the argument is called事件
。You can query the object properties using dot notation. For example,event.previousvalue
返回下拉下的上一个值。这Valuechangeddata
object is not available to callback functions specified as character vectors.
这following table lists the properties of theValuechangeddata
目的。
财产 | 价值 |
---|---|
价值 |
App用户与其最新交互后的下拉组件值。 |
上一个值 |
在App用户与IT进行最新交互之前,下拉式组件值。 |
编辑 |
逻辑值指示是否由于将新值键入下拉组件键入而执行回调。
|
资源 |
执行回调的组件。 |
EventName |
“价值” |
For more information about writing callbacks, see应用程序设计师中的回调。
下拉列
—Drop-down menu opening callback function
''
(默认)|功能handle|单元阵列|角色向量
下拉菜单打开回调函数,指定为以下值之一:
功能句柄。
A cell array in which the first element is a function handle. Subsequent elements in the cell array are the arguments to pass to the callback function.
A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.
此属性指定一个回调函数,当用户单击以打开下拉菜单时执行。此回调的可能用途是动态更新下拉菜单中的条目列表。
此回调函数可以访问有关用户与下拉访问的交互的特定信息。Matlab将此信息传递到下拉式上的data
object as the second argument to your callback function. In App Designer, the argument is called事件
。You can query the object properties using dot notation. For example,event.source
returns the落下
用户与用户进行交互以触发回调的对象。这下拉式上的data
object is not available to callback functions specified as character vectors.
这following table lists the properties of the下拉式上的data
目的。
财产 | 价值 |
---|---|
资源 |
执行回调的组件 |
EventName |
“粪便” |
For more information about writing callbacks, see应用程序设计师中的回调。
Position
—下拉组件的位置和大小
[100 100 100 22]
(默认)|[左底宽度高度]
下拉组件相对于父的位置和大小,指定为向量[左底宽度高度]
。This table describes each element in the vector.
元素 | 描述 |
---|---|
left |
Distance from the inner left edge of the parent container to the outer left edge of the drop-down component |
底部 |
Distance from the inner bottom edge of the parent container to the outer bottom edge of the drop-down component |
宽度 |
下拉组件的左右边缘之间的距离 |
高度 |
Distance between the top and bottom outer edges of the drop-down component |
All measurements are in pixel units.
这Position
值相对于drawable areaof the parent container. The drawable area is the area inside the borders of the container and does not include the area occupied by decorations such as a menu bar or title.
例子:[100 100 100 22]
Version History
matlab命令
You clicked a link that corresponds to this MATLAB command:
通过在MATLAB命令窗口中输入该命令。Web浏览器不支持MATLAB命令。万博1manbetx
您还可以从以下列表中选择一个网站:
如何获得最佳网站性能
选择the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- AméricaLatina(Español)
- Canada(英语)
- 美国(英语)