# Using plot3 to plot 3d vectors

157 visualizaciones (últimos 30 días)
Aleem Andrew el 7 de Sept. de 2020
Comentada: Sulaymon Eshkabilov el 10 de Sept. de 2020
The following code is meant to plot the vectors (4,5,6), (-3,6,-3) and (1,2,3) directed from the origin.
plot3([0 4], [0 5], [0 6], 'k^--',[0 -3], [0 6], [0 -3], 'b^--', [0 1],...
[0 2],[0 3], 'r^-')
xlabel('x'); ylabel('y'); zlabel('z');
In the plot generated, the location of some points does not appear to correspond to the axis numbers. For example, the origin is located at a point where neither x nor y nor z appear to be 0 although the same is not true for the remaining points on the plot (like (-3,6,-3) and (4,5,6)) and the location of points relative to each other seems correct. Can someone explain what is causing this and how this issue can be fixed?
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Sulaymon Eshkabilov el 7 de Sept. de 2020
This one is the correct way of plotting the data points:
point1 = [4,5,6];
point2 = [-3,6,-3];
point3 = [1 2 3];
origin = [0,0,0];
figure;hold on;
plot3([origin(1) point1(1)],[origin(2) point1(2)],[origin(3) point1(3)],'r-^', 'LineWidth',3);
plot3([origin(1) point2(1)],[origin(2) point2(2)],[origin(3) point2(3)],'g-^', 'LineWidth',3);
plot3([origin(1) point3(1)],[origin(2) point3(2)],[origin(3) point3(3)],'b-^', 'LineWidth',3);
grid on;
xlabel('X axis'), ylabel('Y axis'), zlabel('Z axis')
set(gca,'CameraPosition',[1 2 3]);
##### 2 comentariosMostrar NingunoOcultar Ninguno
Aleem Andrew el 10 de Sept. de 2020
Sulaymon Eshkabilov el 10 de Sept. de 2020
It just a pleasure to be be helpful.

Iniciar sesión para comentar.

### Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by