d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > Homework Help > Matlab > Step Function
Add Reply New Topic New Poll
Member
Posts: 3,417
Joined: May 15 2009
Gold: 1,201.69
Sep 27 2015 01:13am
So my prof wants us to learn MatLab.
We need to make a step function.

Now I have been successful making a step function using the heaviside function in MatLab.
However he wants us to make one using a for loop to increment a variable from -15 to 30. Then when that variable gets to 10 the function steps up.
Anyone have any idea how to do this?

Thanks, in advance.

Note: I am not asking anyone to solve this for me or to even provide code, but to give some guidance so I can start with something and at least start wrapping my head around a couple of things.

/e 10fg

This post was edited by marioo1182 on Sep 27 2015 01:26am
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 27 2015 02:24am
Quote
Then when that variable gets to 10 the function steps up.

i'm not clear what your function's requirements are exactly. from what you described, sounds like you want 0 if input < 10, 1 otherwise?

Code
function y = step(x)
if x >= 10
y = 1;
else
y = 0;
end
end


then you can just loop through from -15 to 30.
Member
Posts: 12,427
Joined: Mar 4 2006
Gold: 5,077.00
Sep 27 2015 04:52pm
Think about it this way, create an array for x with values ranging from -15 to 30 then fix a function f with any relation you want that changes at x>=10, write it as a for loop using function and x array.

This post was edited by Xx Shin3d0wn xX on Sep 27 2015 04:53pm
Member
Posts: 3,417
Joined: May 15 2009
Gold: 1,201.69
Sep 28 2015 11:40pm
Quote (Xx Shin3d0wn xX @ 27 Sep 2015 15:52)
Think about it this way, create an array for x with values ranging from -15 to 30 then fix a function f with any relation you want that changes at x>=10, write it as a for loop using function and x array.


This helped greatly. Thank you.
Go Back To Homework Help Topic List
Add Reply New Topic New Poll