interp1 will simply return the corresponding value for each location in C so there are no constraints on the values or ordering of C. You can request the value of the function at the same point a million times with no issue. The ordering of A (the monotonically increasing part of the error) doesn't matter because interp1 will automatically sort A to be increasing (it also re-arranges B so that the values still correspond to A).*Ĭ is simply the locations at which you want to sample the interpolant.
#Matlab interp1 how to
If you did, interp1 doesn't know how to cope with that. You can have a look at my answer in this question for an explanation of what interp1 is doing (there is also a graphical explanation in the answer). It is only necessary that the locations (values in A) are unique so that you don't have multiple values in B for the same value of A. Matlab used to have a clearer documentation for interp1. The input ‘x’ is a vector that contains every sample point, a has the defined values and xq contains the coordinates.
![matlab interp1 matlab interp1](https://i.ytimg.com/vi/c1DJz-89xik/maxresdefault.jpg)
In your example, A contains the location of each data point ( x) and B contains the values of your function at each of those points ( f(x)). aqinterp1(x, a, xq): This returns the interpolated values of the function (one-dimensional) with the help of the linear interpolation method.
![matlab interp1 matlab interp1](http://i.stack.imgur.com/cs6fu.jpg)
![matlab interp1 matlab interp1](https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/21702/versions/1/previews/ba_interp3/ba_interp3_small.png)
With interp1 you are essentially attempting to construct an estimate of a function f(x) using x locations provided by the user as well as their corresponding values ( f(x)). The error (which is less useful) actually propagates up from griddedInterpolant which is used by many interpolation functions and therefore has a generic error message. The error is actually a little mis-leading in this case and is caused by all values in A not being unique (not strictly monotonic).