Using Interp1 - monotonic increasing values

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!

 Accepted Answer

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 Comments

Thanks a lot for the answer. Indeed, that is what I cannot figure. I agree that there are two values for y (diff_flows) at some dates, but that is the way it should be, flow rates are constant for 1 day and then we changed it, so at some points we suddenly changed the flow rate. Now, I just want to drive the y value for some dates in between. Can I use interp1 for that somehow or is there any other command that I can use for extracting those?
Thanks loads!
Just find duplicated y values, and change the x's for them by adding a really tiny bit of noise, like 0.0000001*rand(1). That way you won't have the same x values anymore and it should work.
That should work, I can add noise to the duplicated numbers in this data set! Thanks!
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];
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.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!