trying to plot a more complicated step function
Show older comments
I need an equation for a function y(t) where; y(t) = 0 from 0 < t < 1.25; y(t) = -0.18 from 1.25 < t < 2.5; y(t) = 0 from 2.5 < t < 7.5;
It's not necessarily a matlab question but I can't figure out how to plot this step function in matlab. One equation would be helpful as opposed to a piecewise function.
Answers (1)
Azzi Abdelmalek
on 23 Apr 2016
Edited: Azzi Abdelmalek
on 23 Apr 2016
ts=0.01
t1=0:ts:1.25-ts
t2=1.25:ts:2.5-ts
t3=2.5:ts:7.5
t=[t1 t2 t3]
y=[t1*0 -0.18*ones(size(t2)) 0*t3]
plot(t,y)
or
t=0:ts:7.5
y=-0.18*(heaviside(t-2.5)-heaviside(t-1.5))
plot(t,y)
Categories
Find more on Numerical Integration and Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!