How can I join points within a plot with a line?
이전 댓글 표시
I have this plot that consistes of five vector points with one minimun and one maximum each one. I want to automatically draw a line to join all the maximum points, and all the minimum points horizontally.
I am proceding the following way,
clc,clear
b = datestr(datenum(now),1);
for k1 = 1:5
x(k1) = datenum(addtodate(datenum(b), k1, 'day'));
end
xs = datestr(x,1)
x;
y1 = max([5,10]);
y2 = max([5,10]);
y3 = max([12,17]);
y4 = max([12,16]);
y5 = max([12,17]);
y8 = min([5,10]);
y9 = min([5,10]);
y10 = min([12,17]);
y11 = min([12,16]);
y12 = min([12,17]);
plot(x(1),y1,'-- ys','LineWidth',2,'MarkerEdgeColor','r','MarkerFaceColor','g','MarkerSize',10)
hold on
plot(x(1),y8,'--ys','LineWidth',2,'MarkerEdgeColor','b','MarkerFaceColor','y','MarkerSize',10)
plot(x(2),y2,'-- ys','LineWidth',2,'MarkerEdgeColor','r','MarkerFaceColor','g','MarkerSize',10)
plot(x(2),y9,'--ys','LineWidth',2,'MarkerEdgeColor','b','MarkerFaceColor','y','MarkerSize',10)
plot(x(3),y3,'-- ys','LineWidth',2,'MarkerEdgeColor','r','MarkerFaceColor','g','MarkerSize',10)
plot(x(3),y10,'--ys','LineWidth',2,'MarkerEdgeColor','b','MarkerFaceColor','y','MarkerSize',10)
plot(x(4),y4,'-- ys','LineWidth',2,'MarkerEdgeColor','r','MarkerFaceColor','g','MarkerSize',10)
plot(x(4),y11,'--ys','LineWidth',2,'MarkerEdgeColor','b','MarkerFaceColor','y','MarkerSize',10)
plot(x(5),y5,'-- ys','LineWidth',2,'MarkerEdgeColor','r','MarkerFaceColor','g','MarkerSize',10)
plot(x(5),y12,'--ys','LineWidth',2,'MarkerEdgeColor','b','MarkerFaceColor','y','MarkerSize',10)
datetick('x',1,'keepticks');
title('Wind(Knots) versus Time (dd-mmmm-yyyy)','fontsize',12,'fontweight','b','fontname','times');
xlabel('Time (dd-mmmm-yyyy)','fontweight','b','fontname','times');
ylabel('Wind (Knots)','fontweight','b','fontname','times');
set(gca,'fontname','times')
grid minor
Once again, I want to draw a horizontal line from the first maximum including all the points all the way untill the last number, and the same for the minimum points.
Can you please help?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!