plotting step function with variable step length
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Henrik
el 15 de Dic. de 2014
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)
Respuestas (1)
Guillaume
el 15 de Dic. de 2014
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)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!