How to Define a Piecewise Function in MATLAB?

  • Context: MATLAB 
  • Thread starter Thread starter fiendslyr
  • Start date Start date
  • Tags Tags
    Functions Matlab
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 5K views
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.
 
Physics news on Phys.org
Write a function using an if-else block to define the result based on t.