Specifying a function that is discontinuous?

I have to specify a function, x, that is equal to 1 between t=0 and t=5 and is zero everywhere else. How do I do this?
I specified the part that equals to 1 with the code below: t1=0:0.01:5; x1=1*ones(1,length(t1));
but I need to be able to set the other parts of the plot equal to zero. Thanks

Respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 5 de Dic. de 2012
Editada: Azzi Abdelmalek el 5 de Dic. de 2012
t=-10:0.01:10;
y=zeros(1,numel(t));
y(t>=0 & t<=5)=1
%or you can use heaviside function
t=-10:0.01:10;
y=heaviside(t)-heaviside(t-5)

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 5 de Dic. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by