How to plot a line with specific line slope ?
4 ビュー (過去 30 日間)
古いコメントを表示
採用された回答
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
2022 年 12 月 2 日
I have been trying figure out this, and this seems to be the best solution yet. Kudos!
その他の回答 (1 件)
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?
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


