필터 지우기
필터 지우기

how to draw the line of known slope and intercept

조회 수: 54 (최근 30일)
academy25
academy25 2011년 5월 21일
답변: Amr Aboughazala 2022년 5월 6일
Hello, I have a line which is in the form ax+by+c=0, with a,b and c known. In addition, I have a specific (x,y) point known, and the line should pass through it. How can I draw this line in matlab?

채택된 답변

Walter Roberson
Walter Roberson 2011년 5월 22일
If a*x + b*y + c = 0 then b*y = - c - a*x and then provided b is non-zero, y = -c/b - a/b * x
Then if the line is to pass through a specific (x,y) the only thing you have to worry about is ensuring that the range of x you plot includes the specific x .
For example,
x = 15:41;
y = -19/11 - (-3/2)/11 * x;
plot(x,y)

추가 답변 (4개)

Daniel Shub
Daniel Shub 2011년 5월 22일
I like refline
doc refline

Matt Fig
Matt Fig 2011년 5월 22일
You could also do it using MATLAB's polynomial functions...
% Data
a = -2;
b = 3;
c = 8;
x = 3;
y = -2/3;
% Now the plotting.
pp = [-a,-c]/b; % Polynomial as MATLAB likes it.
X = linspace(x-1,x+1); % Where to plot the line...
pv = polyval(pp,X); % Evaluate the polynomial.
plot(X,pv,'-b',x,y,'*r')

noor
noor 2011년 6월 17일
Hello, I'd like to know the slope for image 2D array. Need I draw line of known the slope? Thanks a lot
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 6월 17일
slope of a 2D array is a completely different concept. Please open a new Question for this, if you have not already done so.

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


Amr Aboughazala
Amr Aboughazala 2022년 5월 6일
for a line ax + by - c
you can draw the line using the coefficients as follows,
y = -(a*x+c) / b

카테고리

Help CenterFile Exchange에서 Polynomials에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by