以编程方式将元素添加到 uilistbox
Add elements to uilistbox programmatically
我正在玩 MATLAB GUI,我想在我的程序生成元素时将元素添加到列表框。我有一个生成数据的函数,我想将这些数据的 "Name" 放在列表框中。这是我的函数:
function [ birdInfo, trackBuff ] = saveParabolaOnFramesPlot( birdInfo, trackBuff , f, listbox)
这是我实际设置元素的方式,但它失败并出现以下错误:
There is no String property on the ListBox class
set(listbox, 'String', stringOfField)
stringOfField
的值只是一个字符串。
以下是我如何从 AppDesigner 代码视图调用此函数:
[app.birdInfo, app.trackBuff ] = saveParabolaOnFramesPlot( app.birdInfo, app.trackBuff , app.birdInfo.aFrame, app.JumpListListBox);
我该如何解决这个问题?
'String'
是 uicontrol
对象使用的 属性,它不同于 AppDesigner 创建的对象。根据 uilistbox
的文档,您需要设置 Items
属性 而不是
此外,如果您想要 追加 一个新项目,您需要获取当前的项目列表(字符串元胞数组)并追加您的新项目在分配它之前。
currentItems = get(listbox, 'Items');
newitems = cat(2, currentItems, stringOfField);
set(listbox, 'Items', newitems)
或者更简单地说:
listboxt.Items{end+1} = stringOfField;
我正在玩 MATLAB GUI,我想在我的程序生成元素时将元素添加到列表框。我有一个生成数据的函数,我想将这些数据的 "Name" 放在列表框中。这是我的函数:
function [ birdInfo, trackBuff ] = saveParabolaOnFramesPlot( birdInfo, trackBuff , f, listbox)
这是我实际设置元素的方式,但它失败并出现以下错误:
There is no String property on the ListBox class
set(listbox, 'String', stringOfField)
stringOfField
的值只是一个字符串。
以下是我如何从 AppDesigner 代码视图调用此函数:
[app.birdInfo, app.trackBuff ] = saveParabolaOnFramesPlot( app.birdInfo, app.trackBuff , app.birdInfo.aFrame, app.JumpListListBox);
我该如何解决这个问题?
'String'
是 uicontrol
对象使用的 属性,它不同于 AppDesigner 创建的对象。根据 uilistbox
的文档,您需要设置 Items
属性 而不是
此外,如果您想要 追加 一个新项目,您需要获取当前的项目列表(字符串元胞数组)并追加您的新项目在分配它之前。
currentItems = get(listbox, 'Items');
newitems = cat(2, currentItems, stringOfField);
set(listbox, 'Items', newitems)
或者更简单地说:
listboxt.Items{end+1} = stringOfField;