user interface - Matlab error when playing a sound -
i'm using matlab gui, i'm recording sound save in folder in c, display recorded sound in folder in listbox when press play on sound wav. matlab gives error error :
************error using audioread (line 74)** ***the filename specified not found in matlab path. error in monitoring_system>play_callback (line 178) [q, fs] = audioread(thisstring); error in gui_mainfcn (line 95) feval(varargin{:}); error in monitoring_system (line 42) gui_mainfcn(gui_state, varargin{:}); error in @(hobject,eventdata)monitoring_system('play_callback',hobject,eventdata,guidata(hobject)) error while evaluating uicontrol callback*************
-the record code:
format shortg c = clock; fix(c); a=num2str(c); year=strcat(a(1),a(2),a(3),a(4),a(5)); month=strcat(a(19),a(20)); day=strcat(a(33),a(34)); hour=strcat(a(48),a(49)); min=strcat(a(63),a(64)); sec=strcat(a(74),a(75)); name=strcat(year,'-',month,'-',day,'-',hour,'-',min,'-',sec); fullpath=fullfile('c:\monitoringsystem',name); wavwrite(y,44100,fullpath); y=[];
the code diplay them in listbox:
d = dir('c:\monitoringsystem\*.wav'); %get files set(handles.listbox1,'string',{d.name})
the code play sound chosen listbox:
allstrings = cellstr( get(handles.listbox1, 'string') ); curvalue = get(handles.listbox1, 'value'); thisstring = allstrings{curvalue}; [q, fs] = audioread(thisstring); soundsc(q,44100);
any how solve problem, keeping save in specific folder. copied recorded sound matlab folder , pressed play in gui wav sound didin't give error.
did try debugging , seeing d
contains after selecting file?
as per documentation, d = dir('c:\monitoringsystem\*.wav');
returns struct
following fields: name
, date
,bytes
, isdir
, datenum
(at least on matlab 2015a). although {d.name}
gives filename correctly, should note relative path only, matlab doesn't file unless it's in active directory.
i'm not entirely sure why went through trouble allstrings
, curvalue
, , thisstring
, if understand correctly you're trying do, suggest 1 of 2 approaches:
define default path (i.e.
c:\monitoringsystem
) in constant, , use when saving\loading:default_path = `c:\monitoringsystem`; %// definition ... fullpath = fullfile(default_path,name); %// when saving ... d = dir(fullfile(default_path,'*.wav')); %// when listing files ... [q, fs] = audioread(fullfile(default_path,{d.name})); %// when reading file
using uigetfile:
[filename,pathname] = uigetfile('*.wav','select wav file'); fullpath = fullfile(pathname,filename);
(and rest similar 1st case)
Comments
Post a Comment