早教吧 育儿知识 作业答案 考试题库 百科 知识分享

做了个MATLABGUI的文件,到buttongrop时候.第一次点击的时候有用,但是就是无法切换两个radiobutton.functionpushbutton1Callback(hObject,eventdata,handles)%hObjecthandletopushbutton1(seeGCBO)%eventdatareserved-tobed

题目详情
做了个MATLAB GUI的文件,到buttongrop时候.第一次点击的时候有用,但是就是无法切换两个radiobutton.
function pushbutton1_Callback(hObject,eventdata,handles)% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global x1
global strname
[filename pathname]=uigetfile({'*.wav','ALL FILES(*.*)'},'选择文件');
if isequal([filename pathname],[0,0])
return;
end
strname=[pathname filename];%选择的声音文件路径和文件名
[x1,fs,bits]=wavread(strname);%temp表示声音数据 Fs表示频率
plot(handles.axes1,x1)
title('原始语音采样后时域信号');
% --- Executes when selected object is changed in uipanel1.
function uipanel1_SelectionChangeFcn(hObject,eventdata,handles)
% hObject handle to the selected object in uipanel1
% eventdata structure with the following fields (see UIBUTTONGROUP)
% EventName:string 'SelectionChanged' (read only)
% OldValue:handle of the previously selected object or empty if none was selected
% NewValue:handle of the currently selected object
% handles structure with handles and user data (see GUIDATA)
global x1
global strname
strname=get(hObject,'string');
axes(handles.axes1);
switch strname
case '采样时域图形'
% axes(handles.axes3);
plot(handles.axes1,x1)
title('原始语音采样后时域信号');
case '频率响应图'
freqz(handles.axes1,x1) %绘制原始语音信号采样后的频率响应图
title('原始语音信号采样后频率响应图');
end
错误信息:
Error using ==> axesInvalid object handle
Error in ==> voice>uipanel1_SelectionChangeFcn at 104axes(handles.axes1);
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> voice at 42 gui_mainfcn(gui_State,varargin{:});
Error in ==>@(hObject,eventdata)voice('uipanel1_SelectionChangeFcn',get(hObject,'SelectedObject'),eventdata,guidata(get(hObject,'SelectedObject')))
Error in ==> hgfeval at 63
feval(fcn{1},varargin{:},fcn{2:end});
Error in ==> uitools.uibuttongroup.childAddedCbk>manageButtons at 80 hgfeval(cbk,source,evdata);
Error while evaluating uicontrol Callback
▼优质解答
答案和解析
错误信息表示axes(handles.axes1); 这句有问题,handles.axes1是不合法的句柄
改成这样试试axes(findobj('tag','axes1'));