How can I create a listbox with the content of an structur/array?

2 ビュー (過去 30 日間)
José Antonio Caldas de la Vega
José Antonio Caldas de la Vega 2020 年 7 月 8 日
回答済み: Jakob B. Nielsen 2020 年 7 月 9 日
I want to create a listbox and the content of the listbox has to be an array (yourcell),
This array will be the filenames inside sFiles.
I have this code:
for i=1:1:length(sFiles)
yourcell={sFiles(i).FileName};
res=uicontrol('Style', 'listbox','Position',[50 200 1000 200],...
'string',yourcell,'max',10,'min',1);
end
Does anybody has an idea why it's not working?
Thanks

回答 (1 件)

Jakob B. Nielsen
Jakob B. Nielsen 2020 年 7 月 9 日
You create the listbox inside a loop. That means every loop iteration, you make a listbox on your selected position with only the i'th index of filename. You need to set up your entire list of items first (e.g. inside the loop), then create your listbox after the loop. For example:
yourcell={sFiles(1).FileName};
for i=2:1:length(sFiles)
yourcell=[yourcell,{sFiles(i).FileName}];
end
res=uicontrol('Style', 'listbox','Position',[50 200 1000 200],...
'string',yourcell,'max',10,'min',1);

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by