2016-12-03 46 views
0

我正在玩MATLAB GUI,我想在程序生成它們時將元素添加到列表框中。我有一個生成數據的函數,我想將這些數據的「名稱」放在列表框中。這裏是我的功能:以編程方式向uilistbox添加元素

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); 

我怎樣才能解決這個問題?

回答

2

'String'uicontrol對象所使用的屬性,它們與AppDesigner創建的屬性不同。基於對uilistbox的文件上,你要設置Items屬性,而不是

此外,如果你想追加一個新的項目,你會希望獲得項目的當前目錄(一個單元陣列的字符串),並在分配它之前追加新的項目。

currentItems = get(listbox, 'Items'); 
newitems = cat(2, currentItems, stringOfField); 
set(listbox, 'Items', newitems) 

或者更簡單地說:

listboxt.Items{end+1} = stringOfField; 
+0

謝謝,這解決了我的問題。我發誓我已經收到了文件,但也許我錯過了這一重要步驟。^_ ^ – Leo91