what is the purpose of u1 and u2 in this code?

15 visualizaciones (últimos 30 días)
omar alrehaili
omar alrehaili el 5 de Dic. de 2020
Comentada: Walter Roberson el 5 de Dic. de 2020
t=-1:0.01:6;
u1=[zeros(1,100),ones(1,601)];
u2=[zeros(1,600),ones(1,101)];
u=u1-u2;
x=10*u;
plot(t,x)

Respuesta aceptada

Star Strider
Star Strider el 5 de Dic. de 2020
They create (1x701) vectors with different numbers of zeros and ones.
The overall effect (that is easily seen if plotted) is to create a square pulse that is equal to 1 from 0 to 5, and 0 elsewhere.
(There are easier and more efficient ways to do this.)
  3 comentarios
Star Strider
Star Strider el 5 de Dic. de 2020
Sure!
The easiest way I can code:
t=-1:0.01:6;
sqwv = (t >= 1) & (t <= 5);
figure
plot(t, sqwv)
grid
ylim(1.1*ylim)
producing the same result as the original code in your Question.
The logical vector created in ‘sqwv’ is converted to numeric when used in a calculation (such as in an argument to the plot function).

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 5 de Dic. de 2020
They are unit step functions with different initial times.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by