声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1026|回复: 2

[编程技巧] 求助 希望帮忙啊xiexiexiexie

[复制链接]
发表于 2012-3-18 16:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
界面为右图      程序代码如下   怎么运行不了啊     求助

function playsound(soundtype,frequency,amp,phase)
Fs=41000;  %设置采样频率
x=[0:1/Fs:1];
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([0,0.01,-200,200]);
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)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - 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)
% eventdata  reserved - 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)
% eventdata  reserved - 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)
% eventdata  reserved - 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)
% eventdata  reserved - 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)
% eventdata  reserved - 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)
% eventdata  reserved - 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)
% eventdata  reserved - 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)
% eventdata  reserved - 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)
% eventdata  reserved - 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)
% eventdata  reserved - 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)
% eventdata  reserved - 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)
% eventdata  reserved - 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)
% eventdata  reserved - 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)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

9L}F~S[]E)O[6VRE6~$]S(C(1).jpg
回复
分享到:

使用道具 举报

发表于 2012-3-18 17:45 | 显示全部楼层
回复 1 # 黄忠林 的帖子

lz的错误信息是什么啊

点评

赞成: 5.0
赞成: 5
  发表于 2012-3-19 00:36
发表于 2012-3-19 20:51 | 显示全部楼层
没有错误信息,gui的程序很多内容,找问题要从错误信息提示开始
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-16 02:59 , Processed in 0.071780 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表