필터 지우기
필터 지우기

Display String Arrays in a Listbox

조회 수: 7 (최근 30일)
Max Müller
Max Müller 2014년 7월 8일
댓글: Max Müller 2014년 7월 9일
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.

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 7월 8일
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!
  댓글 수: 1
Max Müller
Max Müller 2014년 7월 9일
thats the way it works. Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by