Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Unit step function

Subject: Unit step function

From: Hind

Date: 22 Dec, 2010 23:36:38

Message: 1 of 6

How to manually write the code for a matlab unit step function, by
user -written function.
thanks

Subject: Unit step function

From: Miroslav Balda

Date: 23 Dec, 2010 00:03:05

Message: 2 of 6

Hind <hind2007@gmail.com> wrote in message <dff8cf82-4500-4a07-9af5-db6c862cd427@c39g2000yqi.googlegroups.com>...
> How to manually write the code for a matlab unit step function, by
> user -written function.
> thanks

ustep = @(x,range) range>=x;

Mira

Subject: Unit step function

From: Nasser M. Abbasi

Date: 23 Dec, 2010 00:41:57

Message: 3 of 6

On 12/22/2010 3:36 PM, Hind wrote:
> How to manually write the code for a matlab unit step function, by
> user -written function.
> thanks

You could aways use Matlab heaviside

n = -10:10;
y =heaviside(n);
plot(n,y);

or to make the plot more clear, do

t = -1:0.001:1;
y = heaviside(t);
plot(t,y);

or you could do:

t = -1:0.001:1;
y = ones( size(t) ) .* (t >= 0) ;
plot(t,y);


or you could also make a function y(t) which returns 1 if t>=0
and use it. for example, for discrete:

function t1()
close all
n = -10:10;
y = mystep(n);
plot(n,y);
end

function y=mystep(n)
y=n>=0;
end

ps. note heaviside(t) = 1/2 at t=0, sometimes you might want
step(0)=1, you decide which definition you want to use.


--Nasser

Subject: Unit step function

From: Hind

Date: 23 Dec, 2010 08:26:11

Message: 4 of 6

On Dec 23, 3:41 am, "Nasser M. Abbasi" <n...@12000.org> wrote:
> On 12/22/2010 3:36 PM, Hind wrote:
>
> > How to manually write the code for a matlab unit step  function, by
> > user -written function.
> > thanks
>
> You could aways use Matlab  heaviside
>
> n = -10:10;
> y =heaviside(n);
> plot(n,y);
>
> or to make the plot more clear, do
>
> t = -1:0.001:1;
> y = heaviside(t);
> plot(t,y);
>
> or you could do:
>
> t = -1:0.001:1;
> y = ones( size(t) ) .* (t >= 0) ;
> plot(t,y);
>
> or you could also make a function y(t) which returns 1 if t>=0
> and use it. for example, for discrete:
>
> function t1()
> close all
> n = -10:10;
> y = mystep(n);
> plot(n,y);
> end
>
> function y=mystep(n)
> y=n>=0;
> end
>
> ps. note heaviside(t) = 1/2 at t=0, sometimes you might want
> step(0)=1, you decide which definition you want to use.
>
> --Nasser

Thank you too much, but I need plot (heaviside(t)-heaviside(t-td))
this function for step input pulse,
my programe:
t=0:0.001:1;
td=0.3;
y=heaviside(t-td);
plot(t,y)

but the problem the figure not complate, what I can do, please?

Subject: Unit step function

From: Nasser M. Abbasi

Date: 23 Dec, 2010 09:48:12

Message: 5 of 6

On 12/23/2010 12:26 AM, Hind wrote:

>
> Thank you too much, but I need plot (heaviside(t)-heaviside(t-td))
> this function for step input pulse,
> my programe:
> t=0:0.001:1;
> td=0.3;
> y=heaviside(t-td);
> plot(t,y)
>
> but the problem the figure not complate, what I can do, please?
>

may be:

figure();
t=0:0.001:1;
td=0.3;
y=heaviside(t)-heaviside(t-td);
plot(t,y)
ylim([-.1 1.2]);
xlim([-.1 2*td]);

--Nasser

Subject: Unit step function

From: Hind

Date: 23 Dec, 2010 15:32:27

Message: 6 of 6

On Dec 23, 12:48 pm, "Nasser M. Abbasi" <n...@12000.org> wrote:
> On 12/23/2010 12:26 AM, Hind wrote:
>
>
>
> > Thank you too much, but I need plot  (heaviside(t)-heaviside(t-td))
> > this function for step input pulse,
> > my programe:
> > t=0:0.001:1;
> > td=0.3;
> > y=heaviside(t-td);
> > plot(t,y)
>
> > but the problem the figure not complate, what I can do, please?
>
> may be:
>
> figure();
> t=0:0.001:1;
> td=0.3;
> y=heaviside(t)-heaviside(t-td);
> plot(t,y)
> ylim([-.1 1.2]);
> xlim([-.1 2*td]);
>
> --Nasser

Thank you Nasser too much my programe now OK, plot the step input
pulse good:
t=0:0.000001:1;
> td=0.3;
> y=heaviside(t-td);
> plot(t,y)

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us