求助 希望帮忙啊xiexiexiexie
界面为右图 程序代码如下 怎么运行不了啊 求助function playsound(soundtype,frequency,amp,phase)
Fs=41000;%设置采样频率
x=;
switch soundtype=input_1
case 1 %正弦波
y=amp*sin(2*pi*x*frequency+phase);
case 2 %方波
y=amp*sign(sin(2*pi*x*frequency+phase));
case 3 %三角波
y=amp*sawtooth(2*pi*x*frequency+phase,0.5);
otherwise
errordlg('Illegal wave type','Choose errer');
end
plot(x,y);%显示波形
axis();
wavplay(y,Fs,'async'); %播放声音,使用async(异步)模式可以实现发声的混迭
% UIWAIT makes untitled10 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = untitled10_OutputFcn(hObject, eventdata, handles)
% varargoutcell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdatareserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
handles.frequency=str2double(get(hObject,'String'))
guidata(hObject,handles);
% hObject handle to frequency (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of frequency as text
% str2double(get(hObject,'String')) returns contents of frequency as a double
% --- Executes during object creation, after setting all properties.
function frequency_CreateFcn(hObject, eventdata, handles)
% hObject handle to frequency (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
handles.amp=str2double(get(hObject,'String'))
guidata(hObject,handles);
% hObject handle to amp (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of amp as text
% str2double(get(hObject,'String')) returns contents of amp as a double
% --- Executes during object creation, after setting all properties.
function amp_CreateFcn(hObject, eventdata, handles)
% hObject handle to amp (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
handles.phase=str2double(get(hObject,'String'))
guidata(hObject,handles);
% hObject handle to phase (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of phase as text
% str2double(get(hObject,'String')) returns contents of phase as a double
% --- Executes during object creation, after setting all properties.
function phase_CreateFcn(hObject, eventdata, handles)
% hObject handle to phase (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in playsound.
playsound(handles.soundtype,handles.frequency,handles.amp,handles.phase);
% hObject handle to playsound (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton2.
set(handles.popupmenu1,'value',1);
set(handles.edit1,'String','400');
set(handles.edit4,'String','180');
set(handles.edit5,'String','0');
handles.soundtype=1;
handles.frequency=400;
handles.amp=180;
handles.phase=0;
guidata(hObject,handles);
% hObject handle to pushbutton2 (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton3.
close
% hObject handle to pushbutton3 (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on selection change in soundtype.
handles.soundtype=get(hObject,'Value');
guidata(hObject,handles);
% hObject handle to soundtype (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns soundtype contents as cell array
% contents{get(hObject,'Value')} returns selected item from soundtype
% --- Executes during object creation, after setting all properties.
function soundtype_CreateFcn(hObject, eventdata, handles)
% hObject handle to soundtype (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in soundtype.
function soundtype_Callback(hObject, eventdata, handles)
% hObject handle to soundtype (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns soundtype contents as cell array
% contents{get(hObject,'Value')} returns selected item from soundtype
function frequency_Callback(hObject, eventdata, handles)
% hObject handle to frequency (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of frequency as text
% str2double(get(hObject,'String')) returns contents of frequency as a double
% --- Executes on button press in playsound.
function playsound_Callback(hObject, eventdata, handles)
% hObject handle to playsound (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
回复 1 # 黄忠林 的帖子
lz的错误信息是什么啊
没有错误信息,gui的程序很多内容,找问题要从错误信息提示开始
页:
[1]