Multiple 3D trajectories displayed on same axis

3 visualizaciones (últimos 30 días)
Robert J Hanna
Robert J Hanna el 17 de Oct. de 2021
Comentada: Robert J Hanna el 18 de Oct. de 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 comentario
dpb
dpb el 17 de Oct. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Dave B
Dave B el 17 de Oct. de 2021
Editada: Dave B el 17 de Oct. de 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).
  1 comentario
Robert J Hanna
Robert J Hanna el 18 de Oct. de 2021
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.

Iniciar sesión para comentar.

Más respuestas (0)

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