what is the purpose of u1 and u2 in this code?
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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)
0 comentarios
Respuesta aceptada
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
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).
Más respuestas (1)
Walter Roberson
el 5 de Dic. de 2020
They are unit step functions with different initial times.
0 comentarios
Ver también
Categorías
Más información sobre Grid Lines, Tick Values, and Labels en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!