how to interpolate to irregular mesh data
30 ビュー (過去 30 日間)
古いコメントを表示
I want to interpolate 2-D scattered data (24 points) which randomly scattered data on a non-uniform grid of query points. The non-uniform data are inside of a trapezoid. X, Y, and Z are vectors containing scattered (no uniform) sample points and data. (The green points are the scattered data and the red points are the non-uniform grid data inside of trapezoid (Attachment Image)). I defined a regular grid (160 mm *160 mm with space of 10 mm) and then separates the points which are inside of trapezoid. I tried to use "TriScatteredInterp"; however I received this error:
"Z must be a matrix, not a scalar or vector."
I want to know how interpolate the scattered data over the non- uniform grid ( for the trapezoid region)
% X coordinate of scatered data
X=[30 60 75 90 30 60 90 105 15 60 90 120 15 60 105 135 15 75 105 135 15 60 105 150];
% Y coordinate of scatered data
Y=[0 0 0 0 40 40 40 40 70 70 70 70 100 100 100 100 130 130 130 130 160 160 160 160];
% The Z value of scatered data
Z=[855.2 1172.1 1082.3 1078.5 795.9 1638.7 1610.8 1526.8 973.8 2778.9 2231.7 1789.9 1855.3 3852.8 2775.1 1903.7 1519.2 3002.0 2704.5 2226.1 1478.3 3186.9 2263.3 1982.0];
% meshgrid data
[xq,yq]= meshgrid(0:10:160,0:10:160);
% X coordinale of four vertices (trapezoid)
xv=[10 0 160 115 10];
% Y coordinate of of four vertices (trapezoid)
yv=[0 160 160 0 0];
% Supports non-convex and self-intersecting polygons.
in=inpolygon(xq,yq,xv,yv)
% Plot the trapezoid and the data inside of it
plot(xv,yv)
hold on
plot(X, Y,'ro','MarkerSize',10,...
'MarkerEdgeColor','r',...
'MarkerFaceColor',[0,1,0])
ylim([-5 190])
xlim([-5 190])
axis equal
hold on
plot(xq(in),yq(in),'r+')
hold on
plot(xq(~in),yq(~in),'bo')
hold off
% The X coordinates of the grid data inside of trapezoid
XGrid_in=xq(in);
% The Y coordinates of the grid data inside of trapezoid
YGrid_in=yq(in);
%-------------------------------------------------------------
%%Interpolation Method I
%-------------------------------------------------------------
% scattered data interpolant
% transpose the row matrix to vector on
X=X.';
Y=Y.';
Z=Z.';
F = TriScatteredInterp(X, Y, Z,'linear');
VGrid_in = F(XGrid_in,YGrid_in);
%VGrid_in=reshape(VGrid_in,[2898/3,3]);
VGrid_in=squeeze(VGrid_in);
mesh(XGrid_in,YGrid_in,VGrid_in);
colormap jet
shading interp
% hidden off
hold on; plot3(X,Y,Z,'ro'); hold off
s=surf(XGrid_in,YGrid_in,VGrid_in);
s.EdgeColor = 'none';
[C,h] =contourf(xq,yq,vq);
colormap(jet)
colorbar
w = h.LineColor;
h.LineColor = 'none';
set(gcf,'units','centimeters','position',[0 0 9 12])
c=colorbar;
xlim([0 160]);
xlabel('X (mm)')
ylim([0 160]);
ylabel('Y (mm)')
0 件のコメント
採用された回答
Walter Roberson
2017 年 12 月 4 日
You sampled F at a list of (X,Y) points, the column vectors XGrid_in, and YGrid_in, which are not grids (the name is confusing.) You get out the Z at those points. You cannot mesh() a list of scattered points.
To construct a mesh from a list of scattered points, you need to do a triangulation. Or you need to take advantage of any information you know about the connectivity of the points.
I would suggest to you that you should just go ahead and apply F to the full mesh (xq, yq), and then that you set any points that should not have been considered to nan.
3 件のコメント
Yue Liu
2020 年 4 月 28 日
Hello, I wonder what should I put for the v while applying F to the full mesh(xq,yq) as the Z provided by Jamal is only for the 24 scatterred points
Image Analyst
2020 年 4 月 28 日
See my attached demo for scatteredInterpolant.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!