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

lineplot

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?

Best Answer

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
Related Question