Multiple 3D trajectories displayed on same axis

1 次查看(过去 30 天)
Robert J Hanna
Robert J Hanna2021-10-17
评论: Robert J Hanna ,2021-10-18
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 个评论
dpb
dpb 2021-10-17
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.

请先登录,再进行评论。

采纳的回答

Dave B
Dave B 2021-10-17
编辑:Dave B 2021-10-17
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).
  1 个评论
Robert J Hanna
Robert J Hanna 2021-10-18
That was the fix, thank you! But I geniunelly don't know. Ideally, I'll add this to some existing code that calculates other parameters of movement. In that case the values representing the different dives are given in a single column and I am not sure how to differentiate them and visualize them in this same way.

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by