Populate filenames into a GUI listbox..

조회 수: 2 (최근 30일)
Edmund Paul Malinowski
Edmund Paul Malinowski 2015년 11월 19일
댓글: Edmund Paul Malinowski 2015년 11월 19일
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:',...
'SelectionMode','single',...
'ListSize', [160 160],...
'Name', 'Choose Audio File..',...
'ListString',str)
if v
wav_name = str{s}; % File Name Of Selected File
wav_path = which(wav_name); % Path Of Selected File
else
fprintf(1, '\tNo file was selected.\n')
end
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?
Thanks,
Paul..

채택된 답변

Ilham Hardy
Ilham Hardy 2015년 11월 19일
Hi,
To populates the listbox you can use
set(handles.*yourlistboxTag*,'String',*yourarraystr*);
and put the code in the _OpeningFcn of the GUI (created by GUIDE)
  댓글 수: 2
Edmund Paul Malinowski
Edmund Paul Malinowski 2015년 11월 19일
Hey Ilham,
Thanks for your reply. This is the code i put in the OpeningFcn section:
% LOAD WAV FILES INTO LISTBOX..
d = dir('*.wav'); % Select Only ‘.wav’ Files
str = {d.name};
set(handles.listbox1,'String',{str}); %set string
....but it kicks up the following error. Any ideas why?
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)EPM_gui_form('listbox1_CreateFcn',hObject,eventdata,guidata(hObject))
Error using matlab.ui.control.UIControl/set
While setting the 'String' property of 'UIControl':
Cell arrays input to String property may only contain character and numeric matrices.
Error in EPM_gui_form>EPM_gui_form_OpeningFcn (line 66)
set(handles.listbox1,'String',{str}); %set string
Error in gui_mainfcn (line 220)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in EPM_gui_form (line 34)
gui_mainfcn(gui_State, varargin{:});
Edmund Paul Malinowski
Edmund Paul Malinowski 2015년 11월 19일
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

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

추가 답변 (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