Plotting 3D points from numerous arrays

Hello all,
I have 210 arrays each one representing the x,y,z coordinates of a point (70 points). My arrays are named Point_1_x, Point_1_y, Point_1_z, etc.
I want to plot a 3D plot of the 70 points at a specific time (assume 20,1 cell in all arrays.
Is there a way to write a loop for the whole procedure with i ranging from 1 to 70 to create this plot as automatically as possible?
Thank you in advance.

 Respuesta aceptada

Konstantinos Belivanis
Konstantinos Belivanis el 7 de Nov. de 2014

0 votos

Well actually, you appented all the points. What I would like is to show all the points (70 points in one plot) at the same time (t=20) in one plot.

4 comentarios

In the first part, I concatenate all the points to have just 3 arrays to manipulate.
and at the end,
plot3(XatTime,YatTime,ZatTime);
should just be replace by :
plot3(XatTime,YatTime,ZatTime,'+'); % to show the 70 points instead of drawing a line.
And then again, I don't know your data. you said at the same time (t=20). where is your time vector ? what index corresponds in the array Point_1_x/y/z ?
Konstantinos Belivanis
Konstantinos Belivanis el 7 de Nov. de 2014
Editada: Konstantinos Belivanis el 7 de Nov. de 2014
So imagine 210 column arrays with titles Point_1x, etc... and each row represent the specific coordinate at a specific time step. So I would like a loop like this one to create a set of X Y Z coords like that
t=20;
for i=1:70
X_Coords=Point_i_x(t,1);
Y_Coords=Point_i_y(t,1);
Z_Coords=Point_i_z(t,1);
end
and then plot each vector of components?
the problem is that the i in the title of the array should not be written like this.
Any idea?
this should work
t=20;
% init
X_Coords = zeros(70,1);
Y_Coords = zeros(70,1);
Z_Coords = zeros(70,1);
% loop on 70 files for the time t
for i=1:70
X_Coords(i) = eval(sprintf('Point_%d_x(t,1)',i));
Y_Coords(i) = eval(sprintf('Point_%d_y(t,1)',i));
Z_Coords(i) = eval(sprintf('Point_%d_z(t,1)',i));
end
% draw
plot3(X_Coords,Y_Coords,Z_Coords,'+');
Thanks a lot!!! The eval(sprintf('Point_%d_x(t,1)',i)) was what I was looking for :)
Solved!

Iniciar sesión para comentar.

Más respuestas (2)

Orion
Orion el 7 de Nov. de 2014
I don't have data to work with and see the validity of the result, but I guess you need something like
% create array by concatenating the vectors for each directions.
% assuming all Point_1_x, Point_1_y, Point_1_z, etc. are columns vectors.
AllXdat = [];
AllYdat = [];
AllZdat = [];
for i = 1:70
AllXdat = [AllXdat eval(sprintf('Point_%d_x',i))];
AllYdat = [AllYdat eval(sprintf('Point_%d_y',i))];
AllZdat = [AllZdat eval(sprintf('Point_%d_z',i))];
end
% define the time you want to plot, and get the corresponding spatial values,
% assuming the value fot t = 20 is at the 20th position in the vectors : Point_1_x(20),...
mytime = 20;
XatTime = AllXdat(mytime,:);
YatTime = AllYdat(mytime,:);
ZatTime = AllZdat(mytime,:);
% plot at the desired time
plot3(XatTime,YatTime,ZatTime);

1 comentario

Could I add the name of each point next to each point? (to be able to identify them on the graph)?

Iniciar sesión para comentar.

Daniel
Daniel el 7 de Jun. de 2018

0 votos

How can I use Surf to plot 3D graph from a text file. The text is attached and the auto-generated surface is also attached. My problem is drawing the attached auto-generated plot in MATLAB using the attached text file. Please, any help?

Categorías

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by