Clear Filters
Clear Filters

spline interpolation for repeated (non periodic) data?

2 views (last 30 days)
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.

Answers (1)

John D'Errico
John D'Errico on 6 Aug 2017
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 Comment
Madan Kumar
Madan Kumar on 6 Aug 2017
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."

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!