Info

This question is closed. Reopen it to edit or answer.

How to interpolate a sparsely spaced matrix to more fine spaced matrix

1 view (last 30 days)
I have two matrices. One that represents measured values, called meas_data (21x66) and one that represents calculated data, called calc_data (201 x 651). The measured data is taking measurements over the same space, but samples way less frequently (-100 to 100 in increments of 10 in one direction and -325 to 325 in increments of 10 in the other). I want to interpolate a matrix such that the measured data can be compared element wise with the calculated matrix. meaning, I want my measured matrix to interpolate to a matrix that samples at the same spacing as the calculated matrix.
How would I go about doing so? interp2 was my first thought.
  3 Comments
Lawrence Lechuga
Lawrence Lechuga on 25 Apr 2018

That I did. Im not sure what I am misunderstanding. I first defined a mesh grid, then defined the destination size. It throws an error saying "Input grid is not a valid MESHGRID."

[X,Y] = meshgrid(-100:10:100,-325:10:325);
X = X'; Y = Y';
[Xq, Yq] = meshgrid(-100:100,-325:325);
Xq = Xq'; Yq = Yq';
new = interp2(X, Y, meas_data,Xq, Yq);

Answers (1)

Ameer Hamza
Ameer Hamza on 25 Apr 2018
From your code in the comment, the problem is happening because you are transposing the matrics X, Y, Xq and Yq. The documentation on interp2 specifies that X, Y, need to have the same dimension as meas_data. Just remove these transpose operations from your code
[X,Y] = meshgrid(-100:10:100,-325:10:325);
[Xq, Yq] = meshgrid(-100:100,-325:325);
new = interp2(X, Y, meas_data,Xq, Yq);

Community Treasure Hunt

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

Start Hunting!