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

Matlab 如何通过两个按钮读取.wav文件并以其他名称保存?,matlab,wav,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 handl

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

% --- 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_回调中出错(第124行) wavwrite(handles.y、fs、nbits、fullfile(路径名、文件名))

gui_mainfcn中的错误(第96行) feval(varargin{:})

M_播放器错误(第42行) gui_mainfcn(gui_State,varargin{:})

@(hObject,eventdata)M_player中出现错误('Saveb_回调',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]);

您还可以在
Openb_Callback
中使用
handles.y
,而无需在handles结构中初始化或存储它。也许你指的是全局
y
。我希望你的错误不仅仅是因为打字错误:
wavwrtie
,而不是
wavwrite
(在
Saveb\u回调中)。而且,
[START-STOP]
没有在任何地方定义(也不是全局的)。您的变量仍然不一致。检查所有输入和输出,确保正确存储和调用它们。您仍然尝试在某些地方使用
句柄.y
而不是
y
,并且在两个地方拼写错误
句柄(您编写了
handels
)。顺便说一下,对于给定的代码,这两行
guidata(hObject,handels)毫无用处,您可以在生成更多错误之前删除它们。我已将y.handles更改为y,并更正拼写错误的单词,并删除了guidata(),但仍然存在以下错误:错误使用wavwrite>OpenWaveWrite(第169行)无法打开文件。原因:wavwrite(第95行)fid=OpenWaveWrite(波形文件)中的无效参数错误;