How do I fit a surface to this data properly?

1 回表示 (過去 30 日間)
Pablo Fernandez
Pablo Fernandez 2021 年 9 月 16 日
コメント済み: Pablo Fernandez 2021 年 9 月 19 日
Hi,
I have a set of datapoints (x,y,z) to which I want to fit a surface. I dont have a mathematical expression for the surface, so I tried to use the linear interpolation as in:
load ('data.mat')
PTSGRID = 256;
xs = min(x):(max(x)-min(x))/(PTSGRID-1):max(x);
ys = min(y):(max(y)-min(y))/(PTSGRID-1):max(y);
[xq, yq] = meshgrid(xs,ys);
zq = griddata(x,y,z,xq,yq,'linear');
plot3(x,y,z,'mo')
hold on
mesh(xq,yq,zq);
However the fitted surface takes very strange values where there is no data defined, very different from what I would visually expect. Take a look for example at this figure, and the zone I circled:
How can I fit in a better way to avoid this behavior?
Thanks!
  2 件のコメント
darova
darova 2021 年 9 月 17 日
Attach the data
Pablo Fernandez
Pablo Fernandez 2021 年 9 月 17 日
Attached to the original post!

サインインしてコメントする。

回答 (2 件)

KSSV
KSSV 2021 年 9 月 16 日
  3 件のコメント
KSSV
KSSV 2021 年 9 月 16 日
The same link has an example showing how to fit for a surface.
Pablo Fernandez
Pablo Fernandez 2021 年 9 月 16 日
Yes, I understand.
The specific point in my questions is how to get rid of the artifacts that appear when I try to interpolate the points in my dataset.

サインインしてコメントする。


darova
darova 2021 年 9 月 19 日
I don't have this problem
s = load('data.mat');
x = s.x;
y = s.y;
z = s.z;
xx = linspace(min(x),max(x),20);
yy = linspace(min(y),max(y),20);
[x1,y1] = meshgrid(xx,yy);
z1 = griddata(x,y,z,x1,y1);
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
mesh(x1,y1,z1)
  1 件のコメント
Pablo Fernandez
Pablo Fernandez 2021 年 9 月 19 日
Hi, thanks for the answer.
You are not seing the effect in that plot because you are evaluating the interpolation in few points. The reason for the interpolation is to evaluate between the data lines. Try changing 20 for 256 in xx and yy definitions and you will notice the effect when plotting.
Regards

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSmoothing についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by