How to plot a line with specific line slope ?

조회 수: 4 (최근 30일)
Sierra
Sierra 2022년 5월 21일
댓글: Anubhav 2022년 12월 2일
i have a one coordinates (x1,y1).
(actually i have a lot of coordinates.)
what i want to know is how to plot a line with specific line slope and (x1,y1).
thanks!

채택된 답변

Voss
Voss 2022년 5월 21일
You have to decide where the plotted line segment should start and end.
Here's one way you might do that, which is to plot the line between two points whose x-coordinates are a certain amount away from x1:
x1 = 3;
y1 = 4;
% slope = 2:
m = 2;
% plot the point (x1,y1):
plot(x1,y1,'ko','MarkerFaceColor','k');
hold on
% plot a line segment with x going from x1-1 to x1+1.
% note that if x changes by 1, then y changes by m
% (that's the definition of the slope of a line):
plot(x1+[-1 1],y1+m*([-1 1]),'b','LineWidth',2)
% another line segment going from x1-4 to x1+2,
% with the same slope:
plot(x1+[-4 2],y1+m*([-4 2]),'--r')
axis equal
  댓글 수: 1
Anubhav
Anubhav 2022년 12월 2일
I have been trying figure out this, and this seems to be the best solution yet. Kudos!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sam Chak
Sam Chak 2022년 5월 21일
But you can only determine the slope if you know the coordinates of the adjacent points.
Are you trying to plot the vector of a particular point when its coordinate is given?

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by