Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Matlab unit step function

Status
Not open for further replies.

chris414

New Member
I'm just starting with matlab and need to create a unit step function (I've heard Matlab has the "heaviside" function for this built in, but for the life of me I can't find it). Is this an acceptable way to code the unit step function?

Code:
function [r] = heaviside(x)
    s = size(x);
    r = 1:1:s(2);

    for n=1:s(2)

        if(x(n) >= 0)

            r(n) = 1.0;

        elseif (x(n) < 0)

            r(n) = 0.0;

        else
            
            r(n) = 3.0;
        
        end
        
    end
end
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top