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

Image Analyst
Image Analyst 2020년 3월 21일
You forgot to attach your .mat file.
In the meantime, you can check out my attached scatteredInterpolant demo.
Gonzalo Ferrada
Gonzalo Ferrada 2020년 3월 23일
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 2020년 3월 24일
편집: Image Analyst 2020년 3월 24일
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.

댓글을 달려면 로그인하십시오.

 채택된 답변

darova
darova 2020년 3월 23일

1 개 추천

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

Gonzalo Ferrada
Gonzalo Ferrada 2020년 3월 23일
Thanks for your feedback!
It seems that the different scales are indeed the reason of the problem. I tried your code and the cubic interpolation still creates very different results than the original data (see the different colorbar scales in each figure). However, the 'v4' method seems to work more accurately.
Any ideas on why the cubic method is not able to produce similar results?
Thanks!
Try to center data
X = double(x_in - mean(x_in(:)));
Y = double(y_in - mean(y_in(:)));
Gonzalo Ferrada
Gonzalo Ferrada 2020년 3월 23일
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 2020년 3월 23일

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

질문:

2020년 3월 21일

편집:

2020년 3월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by