Backward stairs plot in MATLAB

조회 수: 2 (최근 30일)
Tawichai Premgamone
Tawichai Premgamone 2022년 12월 4일
댓글: Voss 2022년 12월 4일
Hello community,
I have a question about the function "stairs" for plotting in 2D.
When using this function, normally, the horizontal lines (stairs) will break away to the right side of the data points (shown in the red plot), like a zero-order-hold function.
However, I have a situation where the horizontal lines must be on the left side instead (see the blue plot, which I simply made in Paint).
I think many applications might need this kind of backward plot, e.g. when data is obtained after a long measurement window, and the timestamps (plotted on x-axis) are made at the time when the measurement value is available. Each data point represents the value in the past, not the future. Therefore, a normal stairs plot will not be the most appropriate visualisation for this application.
Theoretically, I could also minus the time-axis by 1 sample period, but I wonder if this can be done smartly using a property of the stairs function itself, so I can keep the timestamps unmodified.
Thanks

채택된 답변

Voss
Voss 2022년 12월 4일
편집: Voss 2022년 12월 4일
x = 1:8;
y = [3 1 4 3 7 3 4 2];
stairs(flip(x),flip(y),'-b')
hold on
stairs(x,y,'--r')
legend('Backward','Normal')
ylim([0 8])
  댓글 수: 2
Tawichai Premgamone
Tawichai Premgamone 2022년 12월 4일
Brilliant!!
Thanks a lot Voss.
Voss
Voss 2022년 12월 4일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by