Plotting Multiple Lines from two end points in a matrix without a loop?

I have sets of two end points in xyz coord in a matrix in the form of
V (2,3,418)
so for example V(1,:,1) would call the start point of the first line as [x, y, z ]
and V(2,:,1) would call the end point as [x,y,z]
I can plot this in a loop like
for i = 1:length
plot3(V(:,1,i),V(:,2,i),V(:,3,i))
end
I was wondering if theres a way I can plot this all at once with out a loop?

3 comentarios

one way (which is kind of bad practice) is to make each point separated by a NaN, which interupts the line. This way is still probably better because it doesn't create 418 line objects
example:
Length=418;
V2 = zeros(3*Length, 3);
for i = 1:Length
V2(i*3-2:i*3, :) = [ V(:,:,i); NaN(1,3)];
end
plot3(V2(:,1), V2(:,2), V2(:,3))
this does also end up making every line the same color, in case one of your goals was to keep them different.
The other method would be to switch the third dimension with the second dimension, which took me a while to figure out.
V2 = permute(V, [1,3,2]);
plot3(V2(:,:,1), V2(:,:,2), V3(:,:,3))
the plot or plot3 command will separate each column into its own line if you pass in matrix arguments. getting that to be intuitive is really hard.
Thank You! That is very useful
so I left the tab open for this, and I got thinking again would a quiver3 be more what you're looking for?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Graphics Performance en Centro de ayuda y File Exchange.

Productos

Versión

R2021a

Preguntada:

el 21 de Dic. de 2021

Comentada:

el 25 de Dic. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by