custom use of heavisde?

I want to make a function just like the one in attached photo using heaviside command
The graph i get by using my following code,does not continue after t=2
I am trying my following code:(how can i change this code to get output plot like the attached photo)
clc
clear all
close all
syms t
x=[heaviside(t)-heaviside(t-1)]+heaviside(t-2)
ezplot(x)
axis([-0.5 4 -0.25 1.5])

 Accepted Answer

darova
darova on 14 May 2019
How to atomate it?
x1 = [1 1 -1 -1 1 1];
x2 = [0 1 1 2 2 3];
y = heaviside(x1);
plot(x2,y)
xlim([-0.5 3.5])
axis equal

3 Comments

ABTJ
ABTJ on 14 May 2019
Dear your code gives desierd output but it lacks two main pre reqs
1) time must be symbolic variable
2)output should be plotted by using ezplot command not plot,
as i have to using this function for computing fourier transform that requires symbolic variables
darova
darova on 15 May 2019
Edited: darova on 15 May 2019
Hell im good
syms t
x = heaviside(t-2)-heaviside(t-1)+1;
ezplot(x,[0 3])
xlim([-0.5 3.5])
axis equal
If I recall correctly in R2015a you needed to use fplot() instead of ezplot() for symbolic expressions.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Release

R2015a

Asked:

on 14 May 2019

Commented:

on 18 May 2019

Community Treasure Hunt

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

Start Hunting!