如何读取.wav文件,并通过2个按钮以其他名称保存?

时间:2014-12-03 16:46:59

标签: matlab wav

这是我的打开和保存按钮代码:

% --- Executes on button press in Openb.
function Openb_Callback(hObject, eventdata, handles)
% hObject    handle to Openb (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global filename pathname y fs nbits;
[filename, pathname]=uigetfile('*.wav', 'Select a wave file');
[y, fs, nbits] = wavread(fullfile(pathname, filename));
guidata(hObject,handels);


% --- Executes on button press in Saveb.
function Saveb_Callback(hObject, eventdata, handles)
% hObject    handle to Saveb (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global filename pathname y fs nbits;
[pathname filename]=uiputfile('*.wave', 'Choose a name to save file');
wavwrite(handles.y,fs,nbits,fullfile(pathname,filename));
guidata(hObject,handels);

并得到这些错误:

参考不存在的字段' y'。

M_player中的错误> Saveb_Callback(第124行) wavwrite(handles.y,FS和nbits,完整文件(路径名,文件名));

gui_mainfcn出错(第96行)         feval(varargin {:});

M_player中的错误(第42行)     gui_mainfcn(gui_State,varargin {:});

@(hObject,eventdata)M_player(' Saveb_Callback',hObject,eventdata,guidata(hObject))中的错误

评估uicontrol回调时出错

我通过将代码编辑为以下代码来解决我的问题:

% --- Executes on button press in Openb.
function Openb_Callback(hObject, eventdata, handles)
% hObject    handle to Openb (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global filename pathname y fs nbits;
[filename, pathname]=uigetfile('*.wav', 'Select a wave file');
[y, fs, nbits] = wavread(fullfile(pathname, filename));


% --- Executes on button press in Saveb.
function Saveb_Callback(hObject, eventdata, handles)
% hObject    handle to Saveb (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global filename pathname y fs nbits;
[filename pathname]=uiputfile('*.wave', 'Choose a name to save file');
wavwrite(y , [pathname,filename]);

0 个答案:

没有答案