plotting step function with variable step length
6 次查看(过去 30 天)
显示 更早的评论
I want to do a plot of y as a function of time. Where the values of y are either zero or one and they alternate. The time that y is either zero or one is given by t(n) where I solved for t(n) (a vector of different times). Basically I want to have y(t=0 -> t=t(1)) = 0, then y(t=t(1) -> t = t(2)) = 1, then y(t = t(2) -> t(3)) = 0, and so on. I have already solved for a distribution of the t's. I just don't know how to plot this.
1 个评论
Henrik
2014-12-15
Your notation is difficult to understand, so I don't know exactly what you're asking.
From what I understood, you could make a vector of the t-values, another vector with the y-values, and plot them using
plot(t,y)
example:
t=[1 2 4 6 7 9];
y=[1 1 -1 0 -1 1];
plot(t,y)
回答(1 个)
Guillaume
2014-12-15
One possible way:
t=[2 7 10 15 20]; %for example
x = [0 reshape(repmat(t(1:end-1), 2, 1), 1, []) t(end)];
y = repmat([1 1 0 0], 1, ceil(numel(x)/4));
y = y(1:numel(x));
plot (x, y)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!