필터 지우기
필터 지우기

Using plot3 to plot 3d vectors

조회 수: 181 (최근 30일)
Aleem Andrew
Aleem Andrew 2020년 9월 7일
댓글: Sulaymon Eshkabilov 2020년 9월 10일
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 CenterFile Exchange에서 2-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