Filter löschen
Filter löschen

Using plot3 to plot 3d vectors

191 Ansichten (letzte 30 Tage)
Aleem Andrew
Aleem Andrew am 7 Sep. 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?

Akzeptierte Antwort

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 7 Sep. 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 Kommentare
Aleem Andrew
Aleem Andrew am 10 Sep. 2020
Thanks for your answer
Sulaymon Eshkabilov
Sulaymon Eshkabilov am 10 Sep. 2020
It just a pleasure to be be helpful.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by