3d mesh from vector points

3 次查看(过去 30 天)
Camryn
Camryn 2024-1-5
编辑: Voss 2024-1-6
Hello,
I need help creating a 3d surface mesh for X, Y, Z data points (file provided) and I believe the Z values are vector numbers not matrix
Thanks!

采纳的回答

Voss
Voss 2024-1-5
unzip('formica 50x.asc.zip')
M = readmatrix('formica 50x.asc','FileType','text','Delimiter','\t');
% the file contains two sets of data separated by two lines of text that
% contain some description or something (lines 307208 and 307209, which
% correspond to NaNs in the first column of M), so split M into two
% matrices M1 and M2 using the locations of those NaN values.
idx = find(isnan(M(:,1)));
M1 = M(1:idx(1)-1,:);
M2 = M(idx(2)+1:end,:);
% find the number of consecutive repeated X values in each section of M1,
% and use that to get the number of distinct Y values.
nx = diff(find(diff(M1(:,1))));
assert(all(nx == nx(1)))
nx = nx(1);
ny = size(M1,1)/nx;
% use those sizes to reshape each column of M1.
X = reshape(M1(:,1),nx,ny);
Y = reshape(M1(:,2),nx,ny);
Z = reshape(M1(:,3),nx,ny);
% plot a surface.
figure
subplot(2,1,1)
surf(X,Y,Z,'EdgeColor','none')
xlabel('X')
ylabel('Y')
zlabel('Z')
% now do the same for M2.
nx = diff(find(diff(M2(:,1))));
assert(all(nx == nx(1)))
nx = nx(1);
ny = size(M2,1)/nx;
X = reshape(M2(:,1),nx,ny);
Y = reshape(M2(:,2),nx,ny);
Z = reshape(M2(:,3),nx,ny);
subplot(2,1,2)
surf(X,Y,Z,'EdgeColor','none')
xlabel('X')
ylabel('Y')
zlabel('Z')
  2 个评论
Voss
Voss 2024-1-5
编辑:Voss 2024-1-6
You're welcome! Any questions, let me know.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by