Using Interp1 - monotonic increasing values

1 次查看(过去 30 天)
Hi, I have a data set consisting some dates and value. I would like to use interp1 so that I will be able to expand the values so that the value matrix include some more values corresponding to some more dates in the range of the dates that I already have but I get this error! "The grid vectors are not strictly monotonic increasing." I have attached the command line and the required matrices
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fd = interp1(diff_dates,diff_flows,res2(:,1),'linear');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Have tried everything I can think of and find on the net but no luck
Thanks loads!

采纳的回答

Image Analyst
Image Analyst 2014-8-3
You have some values of diff_dates and res2 that are exact repeats. So when there are 2 y values for a single x value, what's it supposed to do? It doesn't know so it throws an error. Make sure you validate your input arrays or else it's "garbage in, errors out".
  5 个评论
John D'Errico
John D'Errico 2014-8-3
编辑:John D'Errico 2014-8-3
But you have a function that has TWO y values at the same x. What value should your function have in that vicinity?
For example,
x = [0 1 1 2];
y = [1 2 3 4];
Now, I'd like to interpolate at a new value of x, say x = 0.5.
Suppose I arbitrarily adjust those x values to
x = [0 1 1.000000001 2]
Now I can interpolate at x = 0.5, since the function is single valued.
But be careful that you did not adjust the first of those duplicated values, since we would get a different interpolated prediction from the sequence below:
x = [0 1.000000001 1 2]
The point is, the common approach that is unambiguous is to average the y over any duplicates in x, replacing those duplicates with a new sequence
x = [1 1 2];
y = [1 2.5 4];
Image Analyst
Image Analyst 2014-8-3
Good point. I was thinking more like a regression than an interpolation. If you nudged one of the points over and wanted some point in the "in between" area on the right, then it would matter which of the two points got nudged over closest to that point. Maybe for duplicated points she should just replace those two (or multiple) points with one x value and the average of the multiple y values.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by