Effacer les filtres
Effacer les filtres

How to interpolate/regrid 2-D array

12 vues (au cours des 30 derniers jours)
Gonzalo Ferrada
Gonzalo Ferrada le 21 Mar 2020
Modifié(e) : Image Analyst le 24 Mar 2020
Hello,
I am trying to regrid data using a cubic interpolation. I have a 2-D matrix (var_in) with 2 coordinates (x_in and y_in), see the plot below:
I have created the two target 2-D coordinates (x_out and y_out), both with the same dimensions and monotonic. First, I tried using griddata, which I have used for other purposes and works well. However, in this case it did not produce the expected results, see the figure below. (I requested the limit up to 15000 in y_out).
You can notice the original data (var_in) varies from 0 to 1, while griddata produced a variable with very different limits.
Also, I tried using scatteredInterpolant by working around my data, but again it did not produce reasonable results:
As you can see, none of the two methods did not produce results similar to the original data. I tried to use interp2 and interpn but they did not work. I guess it is because x_in and y_in are not meshgrids.
Does anyone have a suggestion on how to solve this?
I am attaching a mat file that includes the original data, its coordinates and the requested output coordinates: x_in, y_in, var_in, x_out, y_out.
Thanks.
  3 commentaires
Gonzalo Ferrada
Gonzalo Ferrada le 23 Mar 2020
Thanks! the mat file should be attached now.
I looked at your code and I understand it does the same that I did using scatteredInterpolant, but did not work for my case.
Image Analyst
Image Analyst le 24 Mar 2020
Modifié(e) : Image Analyst le 24 Mar 2020
Why is x_in a 2-D matrix? I thought it was just a 1-D list of x coordinates, and you had a matching/corresponding list of y values, then you had some data value for each (x,y) pair. Please explain what this all represents:
struct with fields:
var_in: [52×44 single]
x_in: [52×44 double]
x_out: [289×775 double]
y_in: [52×44 single]
y_out: [289×775 single]
Did you already run x and y through meshgrid() to get x_in and y_in? If so, do you have the original x and y. I guess I could get it using unique() if I had to.

Connectez-vous pour commenter.

Réponse acceptée

darova
darova le 23 Mar 2020
Your X and Y variable of very different scales
>> max(x_in(:)) - min(x_in(:))
ans =
5.3750
>> max(y_in(:)) - min(y_in(:))
ans =
2.0106e+04
I tried to scale your X variable
load data_sample.mat
X = double(x_in);
Y = double(y_in);
Z = double(var_in);
x1 = linspace(min(X(:)),max(X(:)),200);
y1 = linspace(min(Y(:)),max(Y(:)),200);
[X1,Y1] = meshgrid(x1,y1);
scale = (max(Y(:))-min(Y(:)))/(max(X(:))-min(X(:)));
Z1 = griddata(X*scale,Y,Z,X1*scale,Y1,'linear');
subplot(121)
surf(X,Y,Z,'edgecolor','none')
view(2)
axis tight
subplot(122)
surf(X1,Y1,Z1,'edgecolor','none')
view(2)
axis tight
linear interpolation cubic interpolation
  4 commentaires
Gonzalo Ferrada
Gonzalo Ferrada le 23 Mar 2020
Perfect! I did that and also scaled down the x_in and x_out as you did. It seems that griddata needs that dx and dy are in the same order of magnitude.
This is the final result:
Thanks for the support!
darova
darova le 23 Mar 2020

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by