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 件のコメント
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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by