插值函数 interp1 interp2

本文详细介绍了MATLAB中的一维插值(interp1)和二维插值(interp2)方法。通过具体实例,展示了如何使用这些函数进行数据插值,并解释了其在科学计算和工程应用中的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、一维插值 interp1

clc;
clear;
close all;

x0=0:1:2*pi;
y0=sin(x0);

x=0:0.5:2*pi;

y = interp1(x0,y0,x,'spline');

figure(1);
plot(x0,y0);hold on;plot(x,y);
grid on;
xlabel('x0');ylabel('y0');title("һά²喵");legend('y0','y');

在这里插入图片描述

2、二维插值 interp2

   搜索域:

   横坐标范围col (-5) ~ (+5)
   纵坐标范围row (-3) ~ (+3)

   值域:

   与上述搜索范围一一对应

   搜索坐标:

   ( x, y)

   返回值:

   搜索坐标在搜索域内取得的值

clc;
clear;
close all;

col = -5:5;
row = -3:3;
[map_x, map_y] = meshgrid(col,row);

for i=1:length(row)
    for j=1:length(col)
        region(i,j) = ((i-1)*length(col)+j)*10;
    end
end

region

%% x:(-5 5)   y:(-3 3)
x=2.4;
y=2.5;
if x>5
    x=5;
elseif x<-5
    x=-5;
end

if y>3
    y=3;
elseif y<-3
    y=-3;
end
    
value = interp2(map_x, map_y, region, x, y);

fprintf("search (%d, %d) : %d\n", x, y, value);


simulink中使用的插值模块: Lookup Tables

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值