# Unit step function in MATLAB - Help!

Thread Starter

#### krow

Joined May 25, 2010
49
Hey guys,

Can anybody help me plot a unit step function in MATLAB? I'm not an experienced programmer and I'm kind of struggling trying to get it right, thanks.

#### jegues

Joined Sep 13, 2010
733
Hey guys,

Can anybody help me plot a unit step function in MATLAB? I'm not an experienced programmer and I'm kind of struggling trying to get it right, thanks.
After a 5 second google of the title of your thread I found this.

Create your own m-file,

Rich (BB code):
function [x]=unitstep(x)

%This is a unit step "function". The vector keeping track of time is the
%input. If time is negative then a zero is returned. If time is zero than
%0.5 is returned. If time is positive then 1 is returned.

if nargin==0 %demo the use of the function if no input is givenx=-10:10;​end

x=x./abs(x); %this performs the same operation as the %matlab "sign"
x(isnan(x))=0;

x=0.5*(x+1);

Thread Starter

#### krow

Joined May 25, 2010
49
After a 5 second google of the title of your thread I found this.

Create your own m-file,

Rich (BB code):
function [x]=unitstep(x)

%This is a unit step "function". The vector keeping track of time is the
%input. If time is negative then a zero is returned. If time is zero than
%0.5 is returned. If time is positive then 1 is returned.

if nargin==0 %demo the use of the function if no input is givenx=-10:10;​end

x=x./abs(x); %this performs the same operation as the %matlab "sign"
x(isnan(x))=0;

x=0.5*(x+1);
Thanks for the link, I saw it weeks ago though. The problem is I'm not familiar with the 'function' command in MATLAB, I just wanted to have a simple function like u(t-1) so I can shift the function by varying 't', convolute it with another signal, etc.

I will have to read and learn how functions in MATLAB work and then do what I need

Similar threads