Populate filenames into a GUI listbox..

2 views (last 30 days)
Hey all,
Although i managed to sort (via help from Star Strider) to get only wav files loaded into a listdlg, i now have a GUI (designed through GUIDE) and need to do the same with the listbox i created on there..
The code i have for the simple listdlg is:
d = dir('*.wav'); % Select Only ‘.wav’ Files
str = {d.name};
[s,v] = listdlg('PromptString','Select a wav file:',...
'ListSize', [160 160],...
'Name', 'Choose Audio File..',...
if v
wav_name = str{s}; % File Name Of Selected File
wav_path = which(wav_name); % Path Of Selected File
fprintf(1, '\tNo file was selected.\n')
Obviously this code won't work with the GUI listbox so could someone point me in the right direction to get this working please :)
I've read a few threads on here and on other websites but i can't get them to work correctly.
I presume the goes in the listbox1_CreateFcn section?

Accepted Answer

Ilham Hardy
Ilham Hardy on 19 Nov 2015
To populates the listbox you can use
and put the code in the _OpeningFcn of the GUI (created by GUIDE)
Edmund Paul Malinowski
Edmund Paul Malinowski on 19 Nov 2015
Never mind :) i sussed it. The following line:
set(handles.listbox1,'String',{str}); %set string
...i had {} around the array name str. Got rid of them and bingo :) so now it reads:
set(handles.listbox1,'String',str); %set string

Sign in to comment.

More Answers (0)


Find more on Interactive Control and Callbacks 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!

Translated by