两条曲线之间的插值(matlab) [英] Interpolation between two curves (matlab)

查看:278
本文介绍了两条曲线之间的插值(matlab)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的.我有以下问题:

我有以下图表的数据.

I have the data of the following plot.

因此,该图的数据文件包含三列. 第2个和第3个x,y点.第一个是这些点属于哪个系统. 在这种情况下,红色表示20年制.蓝色为30年.

So the data file of this plot contains three columns. The 2nd and 3rd ones the x,y points. And the 1st one is to which system those points belong. In this case the red ones are for the system of 20 years. The blue ones for the 30 years.

我想找到的是25年后的曲线.因此,如果我绘制它,它应该在红色和蓝色曲线之间.

What I want to find is the curve at 25 years. So if I plot it it should be between the red and blue curves.

我不知道如何对数据进行插值以获得我想要的东西.实际上我想拥有21,22,... 29年,我想如果我们能在这两者之间找到一段时间,那么该方法应该在20到30之间的任何时间都可以工作.

I have no idea how interpolate the data in order to obtain what I want. Actually I want to have for 21,22,...29 years, I guess if we can find it for a time in between these two, then the method should work for any time between 20 and 30.

PS:我想每条曲线(在这种情况下为红色或蓝色)的插值都非常简单.只需使用interp1(x,y,xx)即可.但是其他维度"(M)发生了什么

PS: I guess the interpolation for each curve (in this case red or blue one) is quite easy. Just using interp1(x,y,xx) will work. But what happened with the other "dimension" (M)

数据.

20.0000    3.4076         0
20.0000    3.4226   99.5405
20.0000    3.4701  196.3360
20.0000    3.5592  287.0781
20.0000    3.6248  328.8516
20.0000    3.6643  348.3373
20.0000    3.7091  367.2823
20.0000    3.7591  385.4784
20.0000    3.8077  402.7170
20.0000    3.8957  437.5221
20.0000    4.0314  506.9907
30.0000    3.6335         0
30.0000    3.6373   49.8884
30.0000    3.6488   99.5405
30.0000    3.6685  148.5936
30.0000    3.7363  243.2204
30.0000    3.7876  287.7398
30.0000    3.8537  329.6097
30.0000    3.8935  349.9452
30.0000    3.9384  368.9776
30.0000    3.9892  387.2576
30.0000    4.0410  404.5759
30.0000    4.1350  439.5416
30.0000    4.2153  474.2420
30.0000    4.2813  509.3309

推荐答案

实际上,通过查看Matlab文档,我发现了一种更简单的方法.您可以使用功能 griddata . (matlab帮助中的文档显示了直观的示例).在公共网格上进行重采样并内插在函数中.

Actually, by looking at the Matlab documentation I found a simpler way. You can use the function griddata. (The doc in matlab help shows visual example). The resampling on a common grid and the interpolation is embedded in the function.

%// First separate (and name your column to identify them better)
t = d(:,1) ;
x = d(:,2) ;
y = d(:,3) ;

%// use the function 'griddata'
[TI,YI] = meshgrid( 20:30 , 0:20:500 ) ; %// change these values to change the grid limits
XI = griddata(t,y,x,TI,YI) ;

%// show result in 3D ... but could be projected in X-Y plane if necessary
plot3(TI,YI,XI , 'Marker','o' )
xlabel('Time') ; ylabel('Y') ; zlabel('X')

代码的最后一行显示此图:

The last line of the code shows this plot:

所有内插数据都在XI矩阵中.检索它们的方式取决于最终要如何组织它们.

All your interpolated data are in the XI matrix. The way to retrieve them depends on how you want to organize them ultimately.


要将所有插值数据放置在与原始表相同组织方式的单个表InterpData中,请使用以下命令:


To place all the interpolated data in a single table InterpData organized the same way of your original table, use the following:

nLine = numel(XI) ;
InterpData = [ reshape(TI,nLine,[]) reshape(XI,nLine,[]) reshape(YI,nLine,[]) ] ;


关于NaN.每当您要求在初始已知值之外进行插值时,它们都会打扰您.
例如,如果原始数据中的时间在[20到30]间隔内,则matlab将很乐意对该间隔内的任何内容进行插值,但是,例如,如果您要求返回time = 19的值,则将返回NaN. Y也是一样,要插值的网格必须在初始范围内. (在此实现中,我们使用由Time (第1列)Y (第3列)组成的基本网格来插值X列)


Regarding the NaNs. They will come to bother you every time you ask to do an interpolation outside of the initially known values.
For example, if your time in the original data is in the [20 to 30] interval, matlab will gladly interpolate anything within that interval, but will return NaN if you ask to return a value for time = 19 for example. Same goes for Y, the grid on which to interpolate has to be within the initial range. (as in this implementation we use a base grid formed by Time (column 1) and Y(column 3), to interpolate the X column).

这篇关于两条曲线之间的插值(matlab)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆