Stair Plot problem
조회 수: 7 (최근 30일)
이전 댓글 표시
I have four data points along a date axis, which I want to plot as a stairs.
the data are
Data = [9;9;10;9]
the dates are in chronological order, but don't really mater here I think.
My problem is that when plotting as
stairs(Dates,Data)
matlab marks six data points instead of the actual four. I realize that this is necessary in order to do the corners, but isn't there a way to keep the line while having the markers only on the actual datapoints.
And more importantly, as it is now the plot rises to 10 (and has a marker at 9 at the same time) before the matching date, and goes back to 9 at the time it should be 10.
Is there any property I need to change in order to get the output I want?
댓글 수: 0
답변 (1개)
Fangjun Jiang
2011년 12월 19일
I guess that is what the way stairs() is designed.
To answer your first part of the question, you probably need to do two steps.
Data=[9;9;10;9];
figure;
stairs(Data);
hold on;
plot(Data,'*');
axis([0 5 8 11]);
I am not very clear about your second part of the question. Maybe this?
Data=[9;9;10;9];
figure;
stairs([Data;Data(end)]);
hold on;
plot(Data,'*');
axis([0 5 8 11]);
댓글 수: 2
Fangjun Jiang
2011년 12월 19일
I think you may have some inconsistency describing your data in your comments. I can think of a way to show the drop of y from 10 to 9 at x=8, but I don't see why x=11 comes to the picture.
%%
Data=[9;9;10;9];
x=[1;3;5;8];
figure;
stairs([x;x(end)+1],[Data;Data(end)]);
hold on;
plot(x, Data,'*');
axis([0 10 8 11]);
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!