⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example_interp1.m

📁 matlab从入门到精通第6章书后源码对初学者很有帮助
💻 M
字号:
% example_interp1.m
% 根据测量的人耳对声音频率的测量数据拟合曲线
% 频率数据(hz)
hz=[20:10:100 200:100:1000 1500 2000:1000:10000];
% 声压水平(db)
spl=[76 66 59 54 49 46 43 40 38 22 ...
    14 9 6 3.5 2.5 1.4 0.7 0 -1 -3 ...
    -8 -7 -2 2 7 9 11 12];
% 使用不同的方法进行插值运算
x=20:10:10000;
yi_linear=interp1(hz,spl,x);
yi_nearest=interp1(hz,spl,x,'nearest');
yi_spline=interp1(hz,spl,x,'spline');
yi_cubic=interp1(hz,spl,x,'cubic');
yi_v5cubic=interp1(hz,spl,x,'v5cubic');
% 绘制不同的图形
% figure1: nearest
subplot(2,2,1);
semilogx(hz,spl,'ko');hold on;
semilogx(x,yi_nearest,'b','linewidth',1.5);
grid on;xlim([10 10000]);hold off;
title('figure1: nearest');
% figure2: spline
subplot(2,2,2);
semilogx(hz,spl,'ko');hold on;
semilogx(x,yi_spline,'r','linewidth',1.5);
grid on;xlim([10 10000]);hold off;
title('figure2: spline');
% figure3: cubic
subplot(2,2,3);
semilogx(hz,spl,'ko');hold on;
semilogx(x,yi_cubic,'r','linewidth',1.5);
grid on;xlim([10 10000]);hold off;
title('figure3: cubic');
% figure4: v5cubic
subplot(2,2,4);
semilogx(hz,spl,'ko');hold on;
semilogx(x,yi_v5cubic,'r','linewidth',1.5);
grid on;xlim([10 10000]);hold off;
title('figure4: v5cubic');
% 绘制听力曲线
figure
semilogx(hz,spl,'ko');hold on;
semilogx(x,yi_linear,'r','linewidth',1.5);
grid on;hold off;
title('threshold of human hearing, linear');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -