Need help with Boolean-type Plot vs Time

조회 수: 10 (최근 30일)
Douglas Carter
Douglas Carter 2015년 5월 5일
댓글: Star Strider 2015년 5월 5일
Right now I'm trying to use the stairs plot, but I can't get it to work the way I want. Not sure exactly how to do this. I have two matrices, one with on/off times every other column e.g [3 10 2 11 5 8 2 16 ...] and another is a dummy matrix I made to associate the on/off times with either "0" for off or "1" for on, i.e. [1 0 1 0 1 0 1 ...]
I would like to make a step plot where the on time is shown at the value "1" for the specified amount of time on the x-axis, then it switches to the off value "0" for the specified amount of off time, etc. So it is essentially a very basic signal.
Any ideas on how I might accomplish this? Thank you.

채택된 답변

Star Strider
Star Strider 2015년 5월 5일
You didn’t post your code so I can’t determine the reason it’s not working. I believe the problem is probably the way you defined your time vector. It has to be increasing in order to provide the type of plot I believe you want, so I used cumsum to create a workable time vector, ‘TS’ here.
This may do what you want (completely guessing though):
T = [3 10 2 11 5 8 2 16];
TS = cumsum(T);
S = [1 0 1 0 1 0 1 0];
figure(1)
stairs(TS, S)
axis([xlim 0 1.1])
  댓글 수: 2
Douglas Carter
Douglas Carter 2015년 5월 5일
That's exactly what I needed, thank you!
Star Strider
Star Strider 2015년 5월 5일
My pleasure!

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by