Matlab的:怎么插不motonic数据 [英] Matlab:how to interpolate non motonic data

查看:154
本文介绍了Matlab的:怎么插不motonic数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些矢量的插值,可以不是单调的问题。

I have a question regarding the interpolation of some vectors which can not be monotonic.

的数据载体看起来如下:

The data vectors looks as follow:

x =        x1 =       y =
   20.0000   21.6000     32
   21.8000   19.8000    132
   22.2000   18.0000    193
   21.4000   16.6000    351
   20.2000   17.0000    576
   20.6000   16.0000    649
   20.3000   13.4000    686
   19.4000   12.2000    806
   16.9000   11.4000   1117
   15.8000   11.2000   1252
   15.6000   10.9000   1281
   15.3000    9.7000   1379
   14.8000    9.2000   1527
   14.5000    8.7000   1577
   12.4000    7.2000   1943
   11.8000    5.0000   2047
   10.4000    3.0000   2282
    5.3000    2.1000   2840
    3.5000    2.0000   3047
    2.6000    1.8000   3140

(小部分)

我会链接到实现Y1,因为这些使用插值:

I would link to achieve 'y1' as interpolation of these using:

y1 = interp1(x,y,x1);

但X和X1不是单调的。

but x and x1 are not monotonic.

Y1应该是只要是

你有如何执行插值的想法?

Have you an idea of how to perform the interpolation?

推荐答案

排序都Y和X如x是单调的。比排序x1和使用它作为presented。

Sort both y and x such as x is monotonic. than sort x1 and use it as presented.

请参阅若跌破code有助于。

See if the code below helps.

[new_x,indx]=sort(x);
new_y=y(indx);
new_x1=sort(x1);

%solves duplicate entries through the unique function (1) or average entries (2)
[temp_new_x,indx]=unique(new_x);

% (1) discard all repeated x values except the last one
new_y=new_y(indx);
new_x=temp_new_x;

% (2) average repeated entries
new_y = arrayfun(@(C) mean(new_y(C==new_x)),temp_new_x);
new_x=temp_new_x;


y1=interp1(new_x,new_y,new_x1);

这篇关于Matlab的:怎么插不motonic数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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