spline interpolation for repeated (non periodic) data?

3 次查看(过去 30 天)
Hi,
I have a matrix (33175x12) with repeated (non-periodic) values (x below). I tried to interpolate but getting error "The data sites should be distinct.". I think sorting data will not be applicable either because I have sorted year-month-day wise. Program is like,
%a=year,b=month,c=day,x=altitude,y=density
a b c x y
1995 1 1 80 8
1995 1 1 81 9
. . . . .
. . . . .
. . . . .
1995 1 1 90 5
1995 1 2 80 7
1995 1 2 81 6
. . . . .
. . . . .
. . . . .
1995 1 2 100 9
1995 1 2 105 8
1995 1 3 75 9
1995 1 3 76 8
. . . . .
. . . . .
. . . . .
1995 1 3 110 8
. . . . .
. . . . .
. . . . .
I am interpolating data as follows,
xx=80:1:105;
Intdata=spline(y,x,xx); Any help/suggestions. Thank you.

回答(1 个)

John D'Errico
John D'Errico 2017-8-6
Um, a spline is a tool that allows you to predict a SINGLE valued function, of the form
y = f(x)
You are calling spline by passing in y in place of x, and x in place of y. So you are creating a relation that is NOT single valued, because thereare multiple values of X at the same locations.
Should spline be smart enough to know that you swapped x and y? How should it be that intelligent? Maybe you WANTED to do that?
Read the help for spline. If you do, it suggests the form:
YY = spline(X,Y,XX);
If you swap the first two arguments, expect problems.
  1 个评论
Madan Kumar
Madan Kumar 2017-8-6
Thank you so much. I also tried it. Problem is that "x" is not monotonic. x repeats but not periodically. Again not all values of x repeat.I am getting error "The data sites should be distinct."

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by