3d mesh from vector points

조회 수: 12 (최근 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
Camryn
Camryn 2024년 1월 5일
Thank you so much!
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