I'm trying to plot the signal u(t)-u(t-1) without heaviside in MATLAB. I've tried to use the if loop but couldn't figure it out.

 Respuesta aceptada

Star Strider
Star Strider el 3 de Oct. de 2018

3 votos

You can use a ‘logical indexing’ approach:
ustp = @(t) +(t>0); % Simple Unit Step Function
t = linspace(-5, 5);
figure
plot(t, ustp(t)-ustp(t-1))
grid
I will let you figure out how it works.

3 comentarios

Anurag Paul
Anurag Paul el 17 de Ag. de 2021
It works by using ‘logical indexing’, so that here, if ‘t’ is greater than 0, the logical comparison returns 1 for all values of ‘t’ greater than 0. When used in computations, the logical 1 becomes numerical 1, so the double function call is not necessary. - copied👆
Vicky
Vicky el 19 de Sept. de 2023
Can you explain how you wrote "@(t) +(t>0)"? It worked perfectly but I'm unsure what the @ is doing here. Thank you so much!
Star Strider
Star Strider el 19 de Sept. de 2023
@Vicky — That is an anonymous function. It works the same way other functions do, and can be called similarly. The ‘@’ creates its function handle.
See the documentation on Anonymous Functions and What is a Function Handle? for details.

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2017a

Preguntada:

el 3 de Oct. de 2018

Comentada:

el 19 de Sept. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by