MATLAB: How can a draw a line between two points

linesmatrixplotscatter

I have a plot that looks like the one below. I want to make vertical lines that connect each individual pair of blue & red points. How can I do this?
PARTIAL CODE:
plot(x, average,'o', 'MarkerEdgeColor', 'b', 'MarkerFaceColor', 'b'); % Blue points
hold on
plot(x, average_2,'o', 'MarkerEdgeColor', 'r', 'MarkerFaceColor', 'r'); % Red points

Best Answer

Assuming that x, average, and average_2 are all row vectors
axes;
hold on;
plot(x, average,'o', 'MarkerEdgeColor', 'b', 'MarkerFaceColor', 'b'); % Blue points
plot(x, average_2,'o', 'MarkerEdgeColor', 'r', 'MarkerFaceColor', 'r'); % Red points
plot([x;x], [average; average_2], '-k');
If the data are column vectors you'll have to transpose the arrays.
Related Question