How to Define a Piecewise Function in MATLAB?

1 reply · 5K views · last reply
fiendslyr
Messages
1
Reaction score
0
So this problem involves computing and plotting the FFT in MATLAB. However, I do not know how to define a piecewise function in MATLAB. The function is as follows:
Code:
y_of_t = {  10cos(2*pi*2500*t), 0 <= t <= 1 msec
                0                         , else

How do I go about defining that function in MATLAB? I know how to do the plotting but just never dealt with piecewise functions in this program. Thanks.
 
Write a function using an if-else block to define the result based on t.