matlab GUI学习

1.命令输入guide
2.建立GUI
3.添加控件
  • Static Text 静态文本框
  • Edit Text 编辑文本框
  • Pushbutton 按钮
  • Radiobutton 单选
  • Axes 坐标轴
4.双击设置控件参数并保存

在这里插入图片描述

5.书写GUI回调函数(callback)代码
% --- Executes on button press in pushbutton1.
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)
close(gcf);
run('sigsample');

单选:

% --- Executes on button press in radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton1
set(handles.radiobutton1,'value',1);
set(handles.radiobutton2,'value',0);

% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton2
set(handles.radiobutton2,'value',1);
set(handles.radiobutton1,'value',0);

打开音频文件:

% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

    [filename, pathname] = uigetfile('*.wav', '*.*','请选择一个音频文件');
    
    if isequal(filename,0) | isequal(pathname,0)
       return;
    end
    
    newstr=[pathname filename];
    set(handles.edit6,'String',newstr);
    
    [x,fs,nbits]=wavread([pathname filename]);
    set(handles.edit9,'String',num2str(fs));
    
    axes(handles.axes1);
    plot(x);
    xlabel('时间');
    ylabel('幅度');
    
    N=length(x);
    fx=fftshift(fft(x));
    w=linspace(-fs/2,fs/2,N);
    axes(handles.axes2);
    plot(w,abs(fx));
    xlabel('f');
    ylabel('幅度');
    
    handles.x=x;
    handles.fs=fs;
    % Choose default command line output for sigsample
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

set(handles.pushbutton7,'enable','on');
set(handles.pushbutton8,'enable','on');

频率转换:

% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%频率转换
x=handles.x;
fs=handles.fs;
fsn=str2double(get(handles.edit7,'string'));
t1=(fs/fsn:fs/fsn:length(x))/fs;     
c=resample(x,fsn,fs) ;   
wavwrite(c,fsn,'after.wav')      
axes(handles.axes1);  
plot(t1,c); 
xlabel('时间');
ylabel('幅度');
    N=length(c);
    fx=fftshift(fft(c));
    w=linspace(-fsn/2,fsn/2,N);
    axes(handles.axes2);
    plot(w,abs(fx));
    xlabel('f');
    ylabel('幅度');

播放:

% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

x=handles.x;
fs=handles.fs;
sound(x,fs);

录音:

% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%录音
fs=str2double(get(handles.edit17,'string'));           %取样频率
duration=str2double(get(handles.edit18,'string'));         %录音时间
% fprintf('Press any key to start %g seconds of recording...\n',duration);
% pause;
fprintf('Recording...\n');
x=wavrecord(duration*fs,fs);         %duration*fs 是总的采样点数
msgbox('录制已经完成','录音','edit19');
wavwrite(x,fs,'recording.wav');%写入音频文件.wav

返回菜单界面:

% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close(gcf);
menu;
6.运行
内容概要:本文系统梳理了多个科研领域的前沿研究与技术实现,重点涵盖FDTD方法中的完美匹配层(PML)研究,以及Matlab/Simulink在电磁、电力、控制、通信、信号处理、图像处理、路径规划、能源系统优化等领域的仿真与算法实现。文中列举了大量基于Matlab和Python的科研案例,如风电功率预测、负荷预测、无人机三维路径规划、电池系统故障诊断、雷达模拟、通信编码、微电网优化调度等,强调结合智能优化算法(如粒子群、遗传算法、深度学习等)提升系统性能。同时,提供了丰富的代码资源与仿真模型,涵盖永磁同步电机控制、逆变器设计、多智能体任务配、虚拟电厂调度等复杂系统,助力科研人员快速开展复现实验与创新研究。; 适合人群:具备一定编程基础,熟悉Matlab/Python工具,从事电气工程、自动化、通信、人工智能、新能源、控制科学等相关领域研究的研发人员及研究生。; 使用场景及目标:① 学习实现FDTD仿真中的PML边界条件以有效抑制数值反射;② 掌握Matlab/Simulink在多物理场建模、控制系统设计与优化算法中的综合应用;③ 借助提供的代码资源完成科研复现、课程设计、竞赛项目或工程原型开发; 阅读建议:此资源以科研实战为导向,不仅提供理论方法,更强调代码实现与仿真验证。建议读者结合自身研究方向,按目录顺序查阅相关模块,下载配套代码进行调试与二次开发,以达到学以致用、融会贯通的目的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值