How can a draw a line between two points?

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

 채택된 답변

Kelly Kearney
Kelly Kearney 2014년 4월 3일

2 개 추천

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.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 3일
편집: Azzi Abdelmalek 2014년 4월 3일

1 개 추천

plot(x, average,'-o', 'MarkerEdgeColor', 'b', 'MarkerFaceColor', 'b');
hold on
plot(x, average_2,'-o', 'MarkerEdgeColor', 'r', 'MarkerFaceColor', 'r');
hold off

카테고리

도움말 센터File Exchange에서 Scatter Plots에 대해 자세히 알아보기

질문:

2014년 4월 3일

댓글:

2014년 4월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by