Multiple 3D trajectories displayed on same axis
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Robert J Hanna
le 17 Oct 2021
Commenté : Robert J Hanna
le 18 Oct 2021
Hello,
I'm trying to visualize a 3D flight trajectory of a bird. I've gathered the positional data for multiple flights and am trying to have multiple flight paths visualized on the same axis with their starting and ending point shown as well.
My code is very elementary but I'm not sure why it isn't working? It usually outputs just the first dive instead of the three?
%3D position data
x1 = DdatafiltDive02(:,1);
y1 = DdatafiltDive02(:,2);
z1 = DdatafiltDive02(:,3);
x2 = DdatafiltDive04(:,1);
y2 = DdatafiltDive04(:,2);
z2 = DdatafiltDive04(:,3);
x3 = DdatafiltDive06(:,1);
y3 = DdatafiltDive06(:,2);
z3 = DdatafiltDive06(:,3);
%removing NaN values
x1_2 = rmmissing(x1);
y1_2 = rmmissing(y1);
z1_2 = rmmissing(z1);
x2_2 = rmmissing(x1);
y2_2 = rmmissing(y1);
z2_2 = rmmissing(z1);
x3_2 = rmmissing(x1);
y3_2 = rmmissing(y1);
z3_2 = rmmissing(z1);
%Fig
f4 = figure;
plot3(x1_2,y1_2,z1_2,x2_2,y2_2,z2_2,x3_2,y3_2,z3_2)
hold on
grid on
xlabel('Meters')
ylabel('Meters')
zlabel('Meters')
plot3(x1_2(1,:),y1_2(1,:),z1_2(1,:),'go', 'MarkerSize', 25)
plot3(x1_2(end,:),y1_2(end,:),z1_2(end,:),'ro', 'MarkerSize', 25)
plot3(x2_2,y2_2,z2_2,'*y')
plot3(x2_2(1,:),y2_2(1,:),z2_2(1,:),'go', 'MarkerSize', 25)
plot3(x2_2(end,:),y2_2(end,:),z2_2(end,:),'ro', 'MarkerSize', 25)
plot3(x3_2,y3_2,z3_2,'*b')
plot3(x3_2(1,:),y3_2(1,:),z3_2(1,:),'go', 'MarkerSize', 25)
plot3(x3_2(end,:),y3_2(end,:),z3_2(end,:),'ro', 'MarkerSize', 25)
hold off
1 commentaire
dpb
le 17 Oct 2021
Attach the data as a .mat file -- nothing seems obvious from the code, although one would expect things to get pretty messy with 3D data, it should still show up.
Réponse acceptée
Dave B
le 17 Oct 2021
Modifié(e) : Dave B
le 17 Oct 2021
There's a typo in your code:
x1_2 = rmmissing(x1);
y1_2 = rmmissing(y1);
z1_2 = rmmissing(z1);
x2_2 = rmmissing(x1);
y2_2 = rmmissing(y1);
z2_2 = rmmissing(z1);
x3_2 = rmmissing(x1);
y3_2 = rmmissing(y1);
z3_2 = rmmissing(z1);
your (x/y/z)2_2 and (x/y/z)3_2 variables are defined based on x1, y1, and z1. So you're just plotting the same thing on top of itself 3 times.
To avoid this kind of problem: Can you think of a way to organize this where you don't label your trajectory number with a number in the variable but instead use an array (maybe a cell array)? Then you can use loops instead of copy/paste (which is prone to this kind of error).
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!