• Register
0 votes

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.


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?

7 5 2
3,870 points

1 Answer

0 votes

Solution :

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


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:


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)



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.

9 7 4
38,600 points

Related questions

0 votes
1 answer 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
asked Aug 4 ArifulIslam 5.7k points
0 votes
1 answer 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.
asked Oct 10 Ahsan 1.4k points
0 votes
1 answer 40 views
Problem : Looking for solution on following issue error: the expression to the left of the equals sign is not a valid target for an assignment
asked Nov 15, 2019 peterlaw 6.9k points
0 votes
1 answer 9 views
Problem: I want to define a variable in Matlab in terms of x. Please help.
asked Oct 10 Ahsan 1.4k points
0 votes
1 answer 94 views
Problem : I have very simple problem that currently looking for the fast implementation in Matlab. I have below array of values: b = floor(rand(5,5).*255) I also have the similarly sized threshold array : b_thresh = floor(rand(5,5).*255) I want to use the ... But, I am facing below error : Operands to || and && operations must be convertible to logical scalar values How can I resolve the issue?
asked Dec 21, 2019 alecxe 7.5k points