Multiple 3D trajectories displayed on same axis
4 views (last 30 days)
Show older comments
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 Comment
dpb
on 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.
Accepted Answer
Dave B
on 17 Oct 2021
Edited: Dave B
on 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).
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!