3d mesh from vector points

7 Ansichten (letzte 30 Tage)
Camryn
Camryn am 5 Jan. 2024
Bearbeitet: Voss am 6 Jan. 2024
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!

Akzeptierte Antwort

Voss
Voss am 5 Jan. 2024
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 Kommentare
Camryn
Camryn am 5 Jan. 2024
Thank you so much!
Voss
Voss am 5 Jan. 2024
Bearbeitet: Voss am 6 Jan. 2024
You're welcome! Any questions, let me know.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by