Using plot3 to plot 3d vectors

347 ビュー (過去 30 日間)
Aleem Andrew
Aleem Andrew 2020 年 9 月 7 日
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?

採用された回答

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2020 年 9 月 7 日
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 件のコメント
Aleem Andrew
Aleem Andrew 2020 年 9 月 10 日
Thanks for your answer
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2020 年 9 月 10 日
It just a pleasure to be be helpful.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by