双插值的MATLAB实现,Matlab中的双重插值

请允许我详细说明我在你的帖子上发表的评论。

如果要使用带有拆分的2个不同函数从输入数组创建输出数组,可以使用数组索引范围,如下面的代码示例所示

x = randn(20,1); %//your input data - 20 random numbers for demonstration

threshold = 5; %//index where you want the change of algorithm

y = zeros(size(x)); %//output array of zeros the same size as input

y(1:threshold) = fun1(x(1:threshold));

y(1+threshold:end) = fun2(x(1+threshold:end));如果您愿意,可以跳过y的预分配,并将其他数据连接到输出的末尾。如果函数返回相对于输入元素数量的不同数量的输出元素,这将特别有用。其语法如下所示。

y = fun1(x(1:threshold));

y = [y; fun2(x(1+threshold:end))];编辑:

在回复下面的帖子时,这是一个完整的例子。 。 。

clc; close all

x = -5:5; %//your x-range

y = [1 1 0 -1 -1 0 1 1 1 1 1]; %//the function to interpolate

t = -5:.01:5; %//sampling interval for output

xIdx = 5; %//the index on the x-axis where you want the split to occur

tIdx = floor(numel(t)/numel(x)*xIdx);%//need to calculate as it is at a different sample rate

out = pchip(x(1:xIdx),y(1:xIdx),t(1:tIdx));

out = [out spline(x((1+xIdx):end),y((1+xIdx):end),t((1+tIdx):end))];

%//PLOTTING

plot(x,y,'o',t,out,'-',[x(xIdx) x(xIdx)], [-1.5 1.5], '-')

legend('data','output','split',4);

ylim ([-1.5 1.5])哪个会给。 。 。

cc554f8d75e4016b3fd2f8358707f499.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值