필터 지우기
필터 지우기

Stair Plot problem

조회 수: 7 (최근 30일)
Patrick Saegesser
Patrick Saegesser 2011년 12월 19일
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?

답변 (1개)

Fangjun Jiang
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
Patrick Saegesser
Patrick Saegesser 2011년 12월 19일
Thanks for your answer. Sorry that I wasn't too clear.
I'll have to try, but I think the first part part should work in two steps as you described. I don't understand why it marks points that are not in the dataset, but as you said, it may the way it is designed.
Regarding the second question, using your axis points, I want the plot to reflect that the Date is always the first point in time on a given level, and the y value remains there until a new event occurs.
Currently, the step from y=9 to y=10 takes place at x=5, remains there on x=8 and drops to y=9 there. Thus I have two points where y=10 and y=9 at the same x value, one at x=5, the other at x=8.
I would like to have it rise to y=10 at x=8 and remain there until x=11, where it then drops back.
Fangjun Jiang
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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by