3d plots with attributes of points

Good evening,
I built in matlab a sets of 3d points with same x and y coordinates and different z and I have used tham in another program wich calculate in those positions some variables (speed and direction of fluid). These points are organized in 12 matrix in wich x and y remain the same, while z varies (with depth).
I want to built a script to represent them and colour them by the value of speed and direction. I read about plot3 whic take in imput 3 vectors and display them in 3d space but I don't know how to afficiently connect the 3d coordinates with attributes.
Can you please give me some advice?
Thank you very much

4 comentarios

Mathieu NOE
Mathieu NOE el 20 de Nov. de 2024
maybe you have a sketch / picture of what you want (and some data to share ?)
The one above is the grid of coordinates I was speaking about.
This is the actual attempt (I'm reading the manual about storing data in multidimensional array and 3plot):
C=table2array(PperMATLABS1)
for i=1:12
for j=3:14
V(:,:,i)=C(:,[1 2 j])
end
end
for k=1:12
plot3(V(:,1,k),V(:,2,k),V(:,3,k),'o')
hold on
end
C=table2array(PperMATLABS1) is the import of the excel sheet in the pictures.
Thank you again
Hey BERNARDO,
You can add columns that represent the color as well as other properties to the matrix that has the coordianates. The column values can be based on your calculation of speed and direction or other parameters as well. This can then be passed to plotting functions like scatter3 which will plot them with the respective color.
An example dataset and plotting is as follows:
% Initialize matrix with 12 rows and 4 columns
data = zeros(12, 4);
% Generate data points with x = y
for i = 1:12
x = i; % x and y are the same
y = i;
z = rand(); % Random z coordinate
color = i; % Unique color for each point
% Assign values to the matrix
data(i, :) = [x, y, z, color];
end
% Plot the points using scatter3
figure;
scatter3(data(:, 1), data(:, 2), data(:, 3), 100, data(:, 4), 'filled');
% Label the axes
xlabel('X Axis');
ylabel('Y Axis');
zlabel('Z Axis');
title('3D Scatter Plot with Unique Colors');
grid on;
BERNARDO
BERNARDO el 22 de Nov. de 2024
Thank you for your suggestion, I'm workin on it!

Iniciar sesión para comentar.

Respuestas (1)

KSSV
KSSV el 21 de Nov. de 2024
Let data be your three columns matrix.
x = data(:,1) ;
y = data(:,2) ;
z = sata(:,3) ;
% Plot as unstructured grid
dt = delaunayTriangulation(x,y) ;
p = dt.Points ;
tri = dt.ConnectivityList ;
F = scatteredInterpolant(x,y,z) ;
z = F(p(:,1),p(:,2)) ;
figure(1)
trisurf(tri,p(:,1),p(:,2),z)
view(2)
shading interp
% Plot as structured grid
xi = linspace(min(x),max(x),300) ;
yi = linspace(min(y),max(y),300) ;
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y) ;
figure(2)
pcolor(X,Y,Z) ;
shading interp

1 comentario

Than you.
I have some questions to ask. I'm sorry but I'm not an enough advance matlab user and it is not completely clear to me the pouropese of the scrip.
taking in imput the coordinates of the 3d points, they have been triangulated in each plane with
delaunayTriangulation(x,y)
my array is made by x,y points disposed on a plane wich are repeated on the z axis (like in the figure).
The coordinates that come from this interpolation are stored in the array named 'Tri', wich is used in the 'trisurf' function, this function create a surface right?
'shading interp' create a colour map in function of the z value.
I would like to know if it is possible to extend your script to interpolate a volume, creating a map like the one in this picture, but wich is continous. I have builted it following the Answer of Jacob Mathew, with a scatter3 plot, adding a column attribute of 0 and 1 to create a temathism for the point.
thank you again for your time

Iniciar sesión para comentar.

Productos

Versión

R2024a

Etiquetas

Preguntada:

el 20 de Nov. de 2024

Comentada:

el 22 de Nov. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by