To plot x y z according to time

25 ビュー (過去 30 日間)
Anne-Laure GUINET
Anne-Laure GUINET 2019 年 1 月 28 日
回答済み: Okbah Alhafez 2021 年 5 月 31 日
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 件のコメント
Luna
Luna 2019 年 1 月 28 日
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?

サインインしてコメントする。

採用された回答

Luna
Luna 2019 年 1 月 29 日
編集済み: Luna 2019 年 1 月 29 日
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

その他の回答 (3 件)

Anne-Laure GUINET
Anne-Laure GUINET 2019 年 1 月 28 日
Thank for your response, it could be clearer with txt file
  2 件のコメント
madhan ravi
madhan ravi 2019 年 1 月 28 日
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 2019 年 1 月 28 日
Thank, it's a mistake

サインインしてコメントする。


Anne-Laure GUINET
Anne-Laure GUINET 2019 年 1 月 30 日
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 件のコメント
Luna
Luna 2019 年 1 月 30 日
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 :)

サインインしてコメントする。


Okbah Alhafez
Okbah Alhafez 2021 年 5 月 31 日
Hi,
my file is in csv format . should i convert the Form , or its ok ?

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by