Adding multiple items in GUI listbox?

조회 수: 7 (최근 30일)
Nirajan Shrestha
Nirajan Shrestha 2017년 12월 26일
편집: Nirajan Shrestha 2017년 12월 26일
Hello Everyone,
I am a newbie at Matlab. I am trying to create a listbox and populate it with audio filenames that is select by the user with upload pushbutton. I did it successfully, however when I try to select a different file by clicking the upload push button, the file names concat. I want the filename in a different line (i.e, value 2 of listbox)
This is what I did!
global SoundNameArray;
[filename, filepath, cCheck] = uigetfile('*.mp3', ... 'Select an audio file','MultiSelect','on');
SoundNameArray = [SoundNameArray filename];
h = msgbox(SoundNameArray);
% Check if the user selected one file or multiple
if(cCheck ~=0)
%Reset selection to first entry
set(handles.select_audio, 'Value', 1);
%Show selected file names in the listbox
set(handles.select_audio,'String', SoundNameArray);
else
end
I would be really grateful if anyone could help. Merry Christmas :)

채택된 답변

Walter Roberson
Walter Roberson 2017년 12월 26일
The third output of uigetfile is the filter index, which will only be 0 if no file is selected.
With multiselect on, the filename will be a simple character vector if only one file is selected but will be a cell array of character vectors if more than one is selected. In order to have your listbox list multiple items you should be passing a cell array of character vectors as the string property. The easiest way to fix the code is to use
SoundNameArray = [SoundNameArray cellstr(fullfile(filepath, filename)) ];
  댓글 수: 1
Nirajan Shrestha
Nirajan Shrestha 2017년 12월 26일
편집: Nirajan Shrestha 2017년 12월 26일
Thank you, Walter. Your answer helped me and I further found out how it (cell array) can be extracted and changed into string when I used audioread using that filename. Thank you so much. Much appreciated.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by