Unit step function in MATLAB - Help!

Discussion in 'Programmer's Corner' started by krow, Jun 7, 2011.

  1. krow

    Thread Starter Member

    May 25, 2010
    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.
  2. jegues

    Well-Known Member

    Sep 13, 2010
    After a 5 second google of the title of your thread I found this.

    Create your own m-file,

    Code ( (Unknown Language)):
    1. function [x]=unitstep(x)
    3. %This is a unit step "function". The vector keeping track of time is the
    4. %input. If time is negative then a zero is returned. If time is zero than
    5. %0.5 is returned. If time is positive then 1 is returned.
    7. if nargin==0 %demo the use of the function if no input is given[INDENT]x=-10:10;
    8. [/INDENT]end  
    10. x=x./abs(x); %this performs the same operation as the %matlab "sign"
    11. x(isnan(x))=0;  
    13. x=0.5*(x+1);
  3. krow

    Thread Starter Member

    May 25, 2010
    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 :p