draw straight line between x1y1 and x2y2 in matlab

To draw a straight line between two points (x1,y1) and (x2,y2) in MATLAB, you can use the plot() function to plot the line. Here's an example code snippet that shows how to do this:

main.m
% Define the two points
x1 = 1;
y1 = 2;
x2 = 5;
y2 = 7;

% Create a vector of x and y values for the line
x = [x1 x2];
y = [y1 y2];

% Plot the line
plot(x, y, 'LineWidth', 2);
177 chars
13 lines

In this example, we first define the two points (x1,y1) and (x2,y2). Then, we create a vector of x and y values for the line by putting the two points into a vector. Finally, we plot the line using the plot() function and specifying a line width of 2. The resulting plot will show a straight line between the two points.

gistlibby LogSnag