• Register
0 votes
296 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?

7 5 2
3,870 points

Please log in or register to answer this question.

1 Answer

0 votes

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.

9 7 4
38,600 points

Related questions

0 votes
1 answer 45 views
45 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, 2020 ArifulIslam 7.5k points
0 votes
1 answer 180 views
180 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, 2020 Ahsan 1.8k points
0 votes
1 answer 35 views
35 views
Problem: I want to define a variable in Matlab in terms of x. Please help.
asked Oct 10, 2020 Ahsan 1.8k points
0 votes
1 answer 79 views
79 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 12 views
12 views
Do I need to use C# Windows Application or can I use Console Applications? Do I only need to save the charts on a server?
asked Sep 17, 2020 Sofi55 1.1k points
0 votes
1 answer 277 views
277 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
1 vote
1 answer 60 views
60 views
Problem: For the following code : E = [5,200]; Selected edge values X = imread('LENNA128.bmp'); N = length(X); Y = false(N+2); for k = 1:numel(E); Y(2:end-1,2:end-1) = X==E(k); Z = Y(1:end-2,2:end-1) | Y(3:end,2:end-1) | Y(2:end-1,3:end) ... )/2); end I get the error message: In an assignment A(:) = B, the number of elements in A and B must be the same Can anyone help me out to solve this problem.
asked Apr 9, 2020 LizzyM 6.1k points
1 vote
1 answer 313 views
313 views
Problem: The maximum number of entry points that any programming structure can have is ____.? Which answer fits in the blank? A) five B) zero C) three D) one
asked Feb 19, 2020 maddi86 5.4k points
0 votes
1 answer 31 views
31 views
Problem: I am new, I need help, can anyone help me? Which of the following consists of rules and standards that define how a database organises data? Data handling Data model Attribute OODB
asked Feb 18, 2020 maddi86 5.4k points
0 votes
1 answer 100 views
100 views
Problem: I have recently started learning matlab from the online tutorials. Currently I have the angle information as shown below for your reference: for i=1:10    angles = func1(val);    polar([angles 0]*pi/180,[15 0],'r'); end The angles is a 512x1 ... and because of lockdown no help is available so posting my question online. I need matlab expert who can help me in fixing my above error.
asked Aug 12, 2020 Raphael Pacheco 4.9k points