How to convert y data for equal intervals of x, z to z data for equal intervals of x, y
49 次查看(过去 30 天)
显示 更早的评论
x and z are tables of size 100x100 using meshgrid.
Values outside the required range of z are treated as NaN.
The y value is the result of the calculation using x and z.
If the result of the calculation for z is a complex number, NaN is processed.
What code should I use to find z for equally spaced x, y?
An error occurs when trying to do 3D interpolation.
I attached the variable as an attachment.
I would greatly appreciate your help.
1 个评论
Madheswaran
2024-11-12,1:52
@Yunjai Could you also post the minimal version of code you were trying to run and the error you were facing?
采纳的回答
Bruno Luong
2024-11-12,7:30
移动:Bruno Luong
2024-11-12,11:18
Rescaling is important when doing scatering interpolation. Avoid unstable extrapolation
load example.mat
XYZ = [X(:), Y(:), Z(:)];
XYZ = rmmissing(XYZ,1);
[minx, maxx] = bounds(X, "all");
[miny, maxy] = bounds(Y, "all");
XN = (XYZ(:,1)-minx)/(maxx-minx);
YN = (XYZ(:,2)-miny)/(maxy-miny);
F = scatteredInterpolant(YN, XN, XYZ(:,3) , 'linear', 'none');
[XNG, YNG] = deal(linspace(0, 1));
ZG = F({YNG, XNG});
XG = minx + XNG*(maxx-minx);
YG = miny + YNG*(maxy-miny);
figure
surf(XG, YG, ZG);
shading interp
hold on
contourf(XG, YG, ZG, 'Zlocation',-1.3)
colorbar
plot3(X(:),Y(:),Z(:),'.b')
view(15,50)
1 个评论
Bruno Luong
2024-11-12,10:50
移动:Bruno Luong
2024-11-12,11:19
If you want exptrapolation I recommend using either the legacy griddata 'v4' or John d'Erric Inpaint_NaNs
更多回答(1 个)
Walter Roberson
2024-11-12,3:36
移动:Walter Roberson
2024-11-12,3:36
load example.mat
XYZ = [X(:), Y(:), Z(:)];
XYZ = rmmissing(XYZ,1);
F = scatteredInterpolant(XYZ(:,1), XYZ(:,2), XYZ(:,3));
[minx, maxx] = bounds(X, "all");
[miny, maxy] = bounds(Y, "all");
[XG, YG] = ndgrid(linspace(minx, maxx), linspace(miny, maxy));
ZG = F(XG, YG);
surf(XG, YG, ZG);
shading interp
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!