Reputation: 141
I have small question concerning gui in matlab. I don't know exactly how to insert/apply list of string to listbox? I don't want to specify fixed list of string in property inspector.
strList = {'aaaa', 'yes', 'no', 'maybe', 'sure'};
or
strList = ['aaaa', 'yes', 'no', 'maybe', 'sure'];
Upvotes: 0
Views: 881
Reputation: 1475
a) To add the item at the end of your list (strList = {'aaaa', 'yes', 'no', 'maybe', 'sure'};
):
strList{end+1} = 'add';
strList =
'aaaa' 'yes' 'no' 'maybe' 'sure' 'add'
b) To insert the item at, for example, n=3
:
strList = [strList(1:n-1), 'insert', strList(n:end)];
strList =
'aaaa' 'yes' 'insert' 'no' 'maybe' 'sure' 'add'
To set the strings into the listbox:
hListBox = uicontrol('Style','List', 'String',strList);
set(hListBox, 'String', strList)
% to get string from ListBox
strList = get(hListBox, 'String');
where hListBox
is the handle for your listbox.
Upvotes: 1