Display String Arrays in a Listbox

22 views (last 30 days)
Hey Guys,
I am a Matlab-Newbie and I have a smale Problem, which I can not solve.
I have 9 String Arrays (all different size) and I want to display them all in one Listbox. The Arrays are saved in an .mat-file. So I need to Load() them and then displazy them all in my Listbox. I would be really tankful if anyone of u could help me. ( and ignore my eng.Skills)
And can u pls answer me the general Question: How can I add things to my Listbox without killing the content, which is allready added.
PS: the command '-append' means the 'save' command does not overwrite an existing mat-file. It just adds new content. Need sth like this for my listbox.

Accepted Answer

Geoff Hayes
Geoff Hayes on 8 Jul 2014
If you want to load a listbox with the contents of 9 string arrays, then (assuming you are using GUIDE to build your GUI) you can load the listbox in your GUI/figure's yourGuiName_OpeningFcn method (where yourGuiName is the name of your GUI)
% load the data from the mat file
load('s1.mat');
load('s2.mat');
% concatenate the string array data into a cell array
data = [cellstr(s1) ; cellstr(s2)];
% load the cell array into the listbox (assumed to be named listbox1
set(handles.listbox1,'String',data);
The above example is for two string arrays only. We use the cellstr on each array to convert the array into a cell array to allow for the concatenation into a cell array since that is the format for the selections into the listbox. If any of the 9 string arrays are already cell arrays, then you can ignore this conversion.
Now in order to append new data to the listbox selections, you can do the following
% get the cell array data that contains all the selections in the listbox
data = get(handles.listbox1,'String');
% append the new data
data = [data ; cellstr('blue')];
% reset the selections
set(handles.listbox1,'String',data);
Try the above and see what happens!

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!