필터 지우기
필터 지우기

Rough interpolation result using Griddata

조회 수: 5 (최근 30일)
Jeroen Vermond
Jeroen Vermond 2016년 10월 30일
댓글: John D'Errico 2016년 10월 31일
I'm using meshgrid and griddata to interpolate scattered data in 2d. The input data seems to be very smooth, but i cannot retrieve such a smooth result with griddata. Does anyone has a suggestion how to to this properly? The figure depicting the results is attached.
Code:
clearvars; close all; clc;
load bulk.mat
X = bulk(:,1);
Y = bulk(:,2);
Z = bulk(:,3);
% now with meshgrid and griddata
xspace = linspace(0,5000,200);
yspace = linspace(0,2e6,160);
[xq,yq] = meshgrid(xspace,yspace);
zq = griddata(X,Y,Z,xq,yq);

채택된 답변

John D'Errico
John D'Errico 2016년 10월 30일
It does not appear that the data you plot is the data you provide in the .mat file. If not, then how can we rationally help you?
The pictures that you show are of a function that is not apparently single valued, in the form z(x,y). The plots you show have a function that rolls over on top of itself. A single valued relation is crucial for griddata to work. (The same requirement would apply for my own gridfit. So don't try gridfit and then get upset when it fails to work well either.)
Note that the data you do provide appears to have a singularity at x=y=0. That will tend to make it difficult to produce a well behaved surface, due to the extremely high slopes.
Lets look at the data you have given us, plotted just as (x,y) pairs.
plot(x,y,'.')
MATLAB does not magically know how to connect these points. All you have given us is a list of those points as scattered pairs. So while your eye may be able to connect them into a surface, all that MATLAB can do is to form a delaunay triangulation in (x,y). It has no idea how the points are connected otherwise.
Here is a small portion of the triangulation that would have been formed:
These long, thin triangles are a problem in interpolation, as well as the choice of which triangles were formed. When you have a relationship with huge gradients, linear interpolation using long thin triangles is never going to work well. That, by the way, is what griddata uses here by default. Yes, it is true that the other methods of griddata will also work poorly on this data. Again, singularities produce problems. If singularities were easy to deal with, they would not have a special name for them, would they?
As well, the fact that x is scaled from 0 to 5e3 and y varies from 0 to 5e6 is also a problem, since it makes linear interpolation that is based on a delaunay triangulation difficult.
Worse, your data appears to be slightly concave along that top edge of the plot in (x,y). The result are some extremely long triangles along that edge. You can see them in the plot above. That will cause major problems.
One solution to the problem might be to rotate the entire data set in 3 dimensions, avoiding any issue of singularities, or single valued functions. That transformation might differ for each problem though, and you would need to understand how to do that.
A better solution would be to build the triangulation more intelligently. Then you could use tools to interpolate that functional form. But that would require you to learn to use such tools.
  댓글 수: 2
Jeroen Vermond
Jeroen Vermond 2016년 10월 31일
편집: Jeroen Vermond 2016년 10월 31일
Dear John, thank you very much for your detailed answer. It gave me some insights on how griddata operates.
For now I have rotated the dataset 45degrees around the x-axis, and scaled the x-value so the xy-data is in the same order of size. The surface made by griddata looks very good, and definitely good enough for my purpose at the moment. The following figure shows 5 graphs with griddata used for 5 datasets (apparantly they do not differ that much):
The only thing to remember is to do the calculations backwards after interpolation later on.
Edit: And scale/rotate your input-values.
John D'Errico
John D'Errico 2016년 10월 31일
Splendid!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by