MATLAB Answers

Create pulses with brackets

3 views (last 30 days)
Uerm
Uerm on 27 Feb 2019
Answered: Walter Roberson on 27 Feb 2019
Hi,
How can I create a pulse function with brackets in MATLAB. I have tried the following, but it obviously just gives 6 different points and thus not pulses.
tSpan = [0 62.5 125 125+62.5 250 300];
gluu = [2e-3 5 2e-3 5 2e-3 5];
The idea is that from time 0 to 62.5, the parameter should have the value 2e-3. From 62.5 to 125 it should be 5. From 125 to 187.5 it should be 2e-3 and so on.

Answers (1)

Walter Roberson
Walter Roberson on 27 Feb 2019
You have four choices:
  1. Decide on a sampling frequency and generate an output vector in which each value is repeated the appropriate number of times. repelem() can help.
  2. Use the data to generate an anonymous function that does conditional tests on the input time to decide what the output should be
  3. Use the data to generate an anonymous function that uses heaviside() to calculate the output given times
  4. Use the symbolic toolbox piecewise() to create a symbolic expression or function to calculate the output given times. Note that matlabFunction() to return anonymous functions cannot handle piecewise() constructs but that matlabFunction with the 'file' output can handle piecewise() but cannot handle vectors of times together with piecewise()

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!