Need help with Boolean-type Plot vs Time

9 次查看(过去 30 天)
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])

更多回答(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