Borrar filtros
Borrar filtros

To plot x y z according to time

64 visualizaciones (últimos 30 días)
Anne-Laure GUINET
Anne-Laure GUINET el 28 de En. de 2019
Respondida: Okbah Alhafez el 31 de Mayo de 2021
Hi,
I have a . txt with 4 colums : time (t), x, y, z which is the x, y, z position of an object according to the time.
I would like to plot the 3D position of this object.
% Data (10)
t= [0,513819900000000
1,01409700000000
1,53027800000000
2,04589800000000
2,54634500000000
3,11879600000000
3,62982200000000
4,14455800000000
4,65201000000000
5,15476100000000]
x=[0,0144918600000000
0,0197000400000000
0,0212137600000000
0,00879137000000000
-0,0430479900000000
-0,173410000000000
-0,293167400000000
-0,315159100000000
-0,306979900000000
-0,291601800000000]
y=[0,0624466500000000
0,0602231400000000
0,0604935700000000
0,0402826200000000
-0,00244453500000000
0,0134661700000000
0,0535583300000000
0,0605951400000000
0,0840618800000000
0,0692208900000000]
z=[0,0765380100000000
0,0890338800000000
0,104488400000000
0,122371500000000
0,181203300000000
0,0617616700000000
-0,0800978800000000
-0,174215400000000
-0,175980100000000
-0,137890000000000]
% Subplot of the deplacement
figure;
subplot(1,3,1); plot(t,x); title ('X to time');
subplot(1,3,2);plot(t,y); title ('Y to time');
subplot(1,3,3);plot(t,z); title ('Z to time');
% 3 plots in 1 figure
figure;
plot3(x,y,z)
hold on
scatter3(x,y,z,[],t,'filled')
box on
grid on
Can I make another plot, more representative of the deplacement or not?
Thank you very much.
AL
  1 comentario
Luna
Luna el 28 de En. de 2019
The data you have provided is not understandable.
Why all x y z and t have 2 columns? (10x2 double array). Can you attach .txt file instead?

Iniciar sesión para comentar.

Respuesta aceptada

Luna
Luna el 29 de En. de 2019
Editada: Luna el 29 de En. de 2019
Hello Anne,
I tried couple of things on your code and change the subplots into vertical instead of horizontal. Looks better.
I have added start and finish points with its legend to see the deplacement of the circles. But in 3D plot it looks very chaotic. I have added rotate3d on so when you right click on the plot go to X-Z view which is the best showing trajectory. I recommend this.
The second and third thing I have tried to put arrows from one point to next point but 136 points are too much so it looked very complex. I don't recommend this.
Also for animation you can use comet3 function. I recommend this to you to understand how your data moves from one to another point.
You can download mArrow3 from this link I have found in FEX.
Please don't forget to read the comments inside the code. Hope those would be helpful.
tableData = readtable('LogPosition.txt');
t = tableData.temps_s_;
x = tableData.x_m_;
y = tableData.y_m_;
z = tableData.z_m_;
% Subplot of the deplacement
figure;
subplot(3,1,1); plot(t,x); title ('X to time'); ylabel('X');
subplot(3,1,2);plot(t,y); title ('Y to time'); ylabel('Y');
subplot(3,1,3);plot(t,z); title ('Z to time'); ylabel('Z');
xlabel('Time');
% 3 plots in 1 figure
figure;
plot3(x,y,z,'-b');
hold on
plot3(x,y,z,'co','LineWidth',0.5);
% plots start point:
plot3(x(1),y(1),z(1),'*g','LineWidth',5);
%plots end point:
plot3(x(end),y(end),z(end),'*r','LineWidth',5);
% add legend:
legend({'Trajectory','Points','Start Point','Finish Point'});
% some axis properties:
box on
grid on
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Object Position');
% Best way is X-Z view.
rotate3d on;
% Best way is X-Z view.
%%%%%%%%%%%%%% This Section written for demo %%%%%%%%%%%%
%% comet3 Function Demo (Working very well)
figure;
comet3(x,y,z);
%% mArrow3 Function Demo (May not be working very well) looks bad.
Array = [x,y,z];
for i = 1:size(Array,1)-1
mArrow3(Array(i,:),Array(i+1,:),'stemWidth',0.0002,'facealpha',0.5,'tipWidth',0.005);
end
%% Or quiver3 Function Demo (May not be working very well, I could not make it work)
quiver3(x,y,z,u,v,w,S,'Color','k');
rotate3d on

Más respuestas (3)

Anne-Laure GUINET
Anne-Laure GUINET el 28 de En. de 2019
Thank for your response, it could be clearer with txt file
  2 comentarios
madhan ravi
madhan ravi el 28 de En. de 2019
If you accept your comment as answer people will think that got an answer to your question so move this answer to the comment section above!
Anne-Laure GUINET
Anne-Laure GUINET el 28 de En. de 2019
Thank, it's a mistake

Iniciar sesión para comentar.


Anne-Laure GUINET
Anne-Laure GUINET el 30 de En. de 2019
Thank you very much Luna !!!
I've just 2 minnor bugs :
  • First, to import the data
tableData = readtable('LogPosition.txt');
t = tableData.temps_s_;
x = tableData.x_m_;
y = tableData.y_m_;
z = tableData.z_m_;
It's doesn't work because it create a 136*1 table named tableData (the values of time, x, y, z are not separated). So I reused my own way to import the data, and it works.
  • Second, with quiver3 because u, v, w do not exist.
But, I'm really statisfied by your answer. Thanks.
  1 comentario
Luna
Luna el 30 de En. de 2019
Your welcome :)
Please use "comment on this answer" section instead of posting an answer.
u v w should be defined for quiver3 but I have never done that before.
If the answer works for you, please accept the answer :)

Iniciar sesión para comentar.


Okbah Alhafez
Okbah Alhafez el 31 de Mayo de 2021
Hi,
my file is in csv format . should i convert the Form , or its ok ?

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by