# The grid vectors do not define a grid of points that match the given values.

202 views

## Problem :

I have some of the time/frequency data and I try to interpolate it using a `interp2` function of Matlab. My data `[F,T,data]` is obtained from the different Matlab routine of a Matlab, spectrogram in case you are interested as below.

``````[~,F,T,data] = spectrogram(...)
data = 10*log10(data);``````

I can plot my data using `surf`. My data is fine, I believe. But interpolating my data seems to be the problem. Even using the `interp2(F,T,data,F,T)` (so actually no interpolating) gives the error as below.

``````interp2(F,T,data,f,t)

Error using griddedInterpolant
The grid vectors do not define a grid of points that match the given values.
Error in interp2>makegriddedinterp (line 228)
F = griddedInterpolant(varargin{:});
Error in interp2 (line 128)``````

What is going wrong here?

## Solution :

Your problem is that you should swap your  `F` and `T`:

`interp2(T,F,data,t,f);`

Your first argument corresponds with the columns of a matrix and a second argument with a rows.

If X and Y are the grid vectors, then your V must be the matrix containing a length(Y) rows and length(X) columns.

As an alternative, you can take a transpose of `data`:

`interp2(F,T,data',f,t);`

Reasoning behind the argument order

`interp2(X,Y,V,Xq,Yq)` is always interpreted as a interpolation of the function, represented by a matrix V, i.e. a sample values and a problem is that the arguments/indexes of the function/matrix are rather supplied in the opposite order:

`matrix(row, column)`

versus

`function(x,y)`

`Here x` (first argument) often represents a horizontal axes and therefore corresponds with a  `column` (second argument) argument and idem for the `y` and `row`.

## Related questions

12 views
Problem: You should not define a class field that is dependent upon the values of other class fields: A) in order to avoid having stale data B) because it is redundant C) because it should be defined in another class D) in order to keep it current
9 views
Problem: I am trying to plot two vectors in MATLAB and it keeps giving me the error that error in plot vector must be same length. What to do? Some one please help.