本文介绍了插值以匹配数据集大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我有两个大小不同的数据集:

If I have two datasets with different sizes for example:

x1 = [0,2,5,10,12,20,15,14] #length = 8
y1 = [0,0.3,0.6,1.1,1.3,2.1,1.6,1.5] #length = 8

x2 = [0,2,4,5,10,12,13,20,18,15,14] #length = 11
y2 = [0.3,0.4,0.5,0.7,1.1,1.3,1.4,2.2,1.6,1.9,1.8] #length = 11

如何获取x1,y1数据以匹配x2,y2数据大小?因此它们的长度均为11.

How can I get the x1,y1 data to match the x2,y2 data size? So they both get length 11.

我看过 scipy.interpolate 及其其他功能.但是我没有得到正确的数字,或者我使用了错误的函数.如果有人知道正确的功能或其他解决方法,那就太好了.

I have had a look at scipy.interpolate and its other functions. But I don't get correct numbers, or I am using wrong functions. If someone knows the correct function or a different method to solve this, then it would be great.

因此,x1,y1的最终长度为11.

So the final lengths of x1,y1 would be 11.

推荐答案

我会使用interp1

I would use interp1

https://uk.mathworks.com/help/matlab/ref/interp1.html

x1i = interp1(1:8,x1,linspace(1,8,11),'spline');

x1i = interp1(1:8, x1, linspace(1,8,11), 'spline');

y1i = interp1(1:8,y1,linspace(1,8,11),'spline');

y1i = interp1(1:8, y1, linspace(1,8,11), 'spline');

这篇关于插值以匹配数据集大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 23:14