필터 지우기
필터 지우기

Draw a line from 2 points and get x and y values

조회 수: 21 (최근 30일)
Karla Haiat
Karla Haiat 2018년 7월 18일
댓글: Karla Haiat 2018년 7월 18일
Hello,
I am trying to draw a line between two points (x1,y1) and (x2,y2), but when plot them together like this: plot([x1,x2],[y1,y2]), I only get the x1,x2 x values and y1,y2 values. I want to draw a line that will give me all point on the whole line. How do I do this?

채택된 답변

Aquatris
Aquatris 2018년 7월 18일
편집: Aquatris 2018년 7월 18일
Simple linear interpolation code;
% 100 points on the line connecting [x1 y1] and [x2 y2]
x = linspace(x1,x2,100); % 100 points between x1 and x2
y = linspace(y1,y2,100); % 100 points between y1 and y2
  댓글 수: 2
Aquatris
Aquatris 2018년 7월 18일
You cannot get all the points since there are infinite points on a line. You either need to settle for a large enough number, like 100 shown in the code, or you can derive the equation of the line and do what you want with the equation of the line.
Karla Haiat
Karla Haiat 2018년 7월 18일
Great, I just needed something simple like this. Appreciate the help.

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

추가 답변 (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