plotting x,y,z vertices as mesh

Hello there,
I have a .xls file that contains x,y,z vertics. The sequence goes something like this: x0,y0,z0,x1,y2,z2,..........x1000,y1000,z1000 (1000data points for each x,y,z)
I am wondering is it possbile to plot all the data using mesh? I plotted only x0,y0,z0 using one of the solutions I reading using trimesh, but there is line between instead of dots. https://www.mathworks.com/matlabcentral/answers/220-3d-plot-from-imported-excel-data
That's what I have so far:
clc;clear;close all;
test = xlsread('data.xls');
x=test(:,2);
y=test(:,3);
z=test(:,4);
x = rand(100,1); % Sample x data
y = rand(100,1); % Sample y data
z = exp(-(x-0.5).^2-(y-0.5).^2); % Sample z data (a 2-D Gaussian)
tri = delaunay(x,y); % Create a 2-D triangular mesh
trimesh(tri,x,y,z); % Plot the mesh in 3-D
Any suggestions and helps please?
Thanks in advance

1 Comment

That approach should work, provided that you remove those 'Sample' lines.
Can you attach your data.xls for testing?

Sign in to comment.

Answers (1)

clc;clear;close all;
test = xlsread('data.xls');
x=test(:,2);
y=test(:,3);
z=test(:,4);
tri = delaunay(x,y); % Create a 2-D triangular mesh
figure
trimesh(tri,x,y,z); % Plot the mesh in 3-D
figure
triplot(tri,x,y);
figure
trisurf(tri,x,y,z); % Plot the surface in 3-D
shading interp

9 Comments

Thanks for the response! I tried scatter3 and it gives closes to what I want! is there a way to plot all the vertics for each x,y,z as I described eariler?
Thanks!
Didn't the given code work?
It worked with the 3 columns only. I have sequence like the following: for each row there is x0,y0,z0,x1,y2,z2,..........x1000,y1000,z1000 (1000data points for each x,y,z), each x,y,z are seperated by 3. I would like to plot the first row for testing as of now (but eventually would like to be able to each row).
I was testing something like this
for i=1:3
x=i+3;
y=i+3;
z=i+3;
a=test(:,x);
b=test(:,y);
c=test(:,z);
scatter3(a,b,c,'*')
hold on
end
Can you give me some help on this?
for i = 1:3:1000-2
a = test(:,i);
b = test(:,i+1);
c = test(:,i+2);
scatter3(a,b,c, '*');
hold on
end
However, this could also be
a = test(:,1:3:1000-2);
b = test(:,2:3:1000-1);
c = test(:,3:3:1000);
scatter3(a(:), b(:), c(:), '*');
or
temp = reshape(test(:,1:999).', 3, :);
scatter3(temp(1,:), temp(2,:), temp(3,:), '*');
Thanks for the response! I am testing it but I do not know it seems it only plot half of the data?
Sorry my bad! I figured it now! I only put half of the data!
Oh, wait, you said 1000 points each, not 1000 columns total. Using the shortest form, then:
temp = reshape(test.', 3, :);
scatter3(temp(1,:), temp(2,:), temp(3,:), '*');
Thanks!
I am also just wondering if its possbile to label the x0,y0,z0,x1,y1,z1.....for each data point? Would it be a massive point?

Sign in to comment.

Categories

Products

Tags

Asked:

on 10 Mar 2020

Commented:

on 11 Mar 2020

Community Treasure Hunt

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

Start Hunting!