Written and maintained by CASRAI Editorial Board
Published · Last updated
On this page
Who this is for: researchers and analysts who typed “MATLAB integrator” and need to know which of four different things they mean, then run it. Short answer: in Simulink, the Integrator block integrates a signal over time; in MATLAB code, integral integrates a function between limits and trapz integrates sampled data.
Ask CASRAI · free to tryQuestion about this guide? Ask CASRAI answers with linked sources. 2 free questions a day, no account.
Which MATLAB integrator do you need?
“Integrator in MATLAB” is used for several tools that live in different places. Each row below is taken from the current MathWorks documentation (read 2026-11-08).
| You have | Use | Where it lives | What it does |
|---|---|---|---|
| A signal in a block diagram, continuous time | Integrator block | Simulink | Integrates its input over time as a dynamic system with one state, initialised to 0 by default |
| A signal in a purely discrete model | Discrete-Time Integrator block | Simulink | Integrates or accumulates a signal in a discrete model; Forward Euler is the default method |
A function you can write as @(x) ... |
integral(fun,xmin,xmax) |
MATLAB | Numerical integration by global adaptive quadrature |
| Measured or sampled points | trapz(X,Y) |
MATLAB | Trapezoidal integration of the values; cumtrapz also returns the intermediate values |
What is the purpose of an integrator?
An integrator accumulates a quantity over time or over an interval: given a rate, it produces the total. In the Simulink Integrator block the relation is x'(t) = u(t), y(t) = x(t), x(t0) = x0, where u is the input, y the output and x0 the initial condition. Typical research uses are turning a modelled rate (for example a velocity) into a state (position) inside a dynamic model, or computing an area under a measured curve.
Can MATLAB perform integration?
Yes. Base MATLAB integrates functions numerically with integral and sampled data with trapz; the Integrator block is the Simulink route. For worked coverage of numerical and symbolic integration in code, see our guide to integrating in MATLAB, and for the older adaptive routine see MATLAB quad.
How does the Integrator block work in Simulink?
The block treats integration as a dynamic system with one state. The solver chosen in the Configuration Parameters, Solver pane determines the numerical output, so the same block can give slightly different results under different solvers. For an overview of Simulink itself, see MATLAB and Simulink.
Ports
- Input: the signal to integrate (no direct feedthrough).
- External reset: a Boolean port that appears when the External reset parameter is set; it has direct feedthrough.
- Initial condition (x0): appears when Initial condition source is external.
- Output: the integrated value.
- Saturation port: appears with Show saturation port.
- State port: appears with Show state port.
- MathWorks, NASA Ames Research Center Develops Flight Software for Lunar Atmosphere Dust Environment Explorer, read 2026-11-08.
Initial condition
Initial condition source is internal by default, with an Initial condition parameter whose default is 0. Choose external to feed x0 in through a port. The initial condition cannot be inf or NaN.
External reset modes
| Mode | The state resets when |
|---|---|
| none (default) | never |
| rising | the reset signal goes from zero or negative to positive |
| falling | the reset signal goes from positive to zero or negative |
| either | the signal changes between zero and nonzero, or changes sign |
| level | the reset signal is nonzero, including the step where it drops to zero |
| level hold | the reset signal is nonzero at the current step |
Limiting the output (windup)
Limit output is off by default. When it is on, the output is bounded by the upper and lower saturation limits (defaults inf and -inf), and integration stops at a limit, which prevents windup. With Show saturation port enabled, the port outputs 1 at the upper limit, 0 when not limited and -1 at the lower limit. A variant, the Integrator Limited block, has Limit output on by default with limits 1 and 0.
State port and algebraic loops
Show state port exposes the block’s state. MathWorks documents it for two uses: avoiding algebraic loops in self-resetting integrators, and passing states between enabled subsystems.
Other parameters
Absolute tolerance is auto by default, which uses the value in Configuration Parameters; a scalar or vector overrides it. Zero-crossing detection is on by default. State Name defaults to an empty entry.
Continuous versus discrete
For a purely discrete model, MathWorks directs you to the Discrete-Time Integrator block instead. Its methods, with T the sample time, are:
- Forward Euler (default): x(n+1) = x(n) + K·T·u(n), y(n) = x(n); no direct feedthrough on input port 1.
- Backward Euler: y(n) = y(n-1) + K·T·u(n); direct feedthrough.
- Trapezoidal: approximates 1/s as (T/2)(z+1)/(z-1); direct feedthrough.
Sample time defaults to -1 (inherited); 0 is not allowed because it denotes continuous time.
Step-by-step: integrate in MATLAB code
Integrate a function with integral
- Define the function as an anonymous function that accepts a vector and returns a vector, using element-wise operators (
.*,.^), not matrix ones. See anonymous functions in MATLAB. - Call
integral(fun,xmin,xmax); limits may beInf.
fun = @(x) exp(-x.^2).*log(x).^2;
q = integral(fun,0,Inf) % q is approximately 1.9475
By default integral uses AbsoluteTolerance 1e-10 and RelativeTolerance 1e-6, and ArrayValued is false; Waypoints can be supplied for difficult integrands.
Integrate sampled data with trapz
X = 0:pi/100:pi;
Y = sin(X);
Q = trapz(X,Y) % Q = 1.9998
trapz(Y) assumes unit spacing, trapz(X,Y) uses the coordinates in X, and trapz(X,Y,dim) integrates along dimension dim. trapz returns only the final value, reducing the integrated dimension to size 1; use cumtrapz to keep the intermediate values.
Step-by-step: set up the Integrator block
- Add an Integrator block to your model and connect the signal to be integrated to its input.
- Choose the solver in Configuration Parameters, Solver pane; the block’s numerical output depends on it.
- Set the Initial condition source (internal or external) and the initial value if internal.
- If the state must restart, set External reset to one of the modes in the table above and wire a Boolean signal to the reset port.
- If the state must stay within bounds, turn on Limit output and set the upper and lower saturation limits.
- Run the simulation and inspect the output signal.
Reading the output
The block’s output y(t) equals its state x(t): the accumulated integral of the input since the initial condition, or since the last reset. For integral and trapz the result is the definite integral over the interval given; trapz on a vector gives a scalar and on a matrix gives a row vector (or a column when dim is 2).
Troubleshooting
- Error from
integralabout vector input: the function handle must accept a vector and return a vector; replace*,/and^with.*,./and.^. - Algebraic loop around a self-resetting Integrator: enable Show state port, which MathWorks documents for this case.
- Output grows without bound against a physical limit: turn on Limit output so integration stops at the limit.
- Initial condition rejected: it cannot be inf or NaN.
- Need a dynamic model solved from equations rather than blocks: see the ODE solver coverage in solving ODEs with deSolve in R for the equivalent workflow in R.
FAQ
Can MATLAB perform integration?
Yes: integral for functions, trapz for sampled data, and the Integrator block in Simulink for signals over time.
What is the purpose of an integrator?
It accumulates an input over time or an interval, so a rate becomes a total or a state.
How does the Integrator block work in Simulink?
It models x'(t) = u(t) with one state, initialised to 0 by default, with the solver setting determining the numerical result.
What is the difference between the Integrator and Discrete-Time Integrator blocks?
The Integrator is continuous-time; the Discrete-Time Integrator is for purely discrete models and uses Forward Euler, Backward Euler or Trapezoidal methods with a sample time.
Does NASA use Simulink?
Yes. MathWorks publishes a user story in which NASA Ames Research Center engineers developed flight software models for the Lunar Atmosphere Dust Environment Explorer (LADEE) in Simulink and used Simulink Coder and Embedded Coder to generate more than 26,000 lines of C code from their Simulink controller models. That is one documented project, not a statement about every NASA program.
Sources
- MathWorks, Integrator block, read 2026-11-08.
- MathWorks, Discrete-Time Integrator block, read 2026-11-08.
- MathWorks, integral, read 2026-11-08.
- MathWorks, trapz, read 2026-11-08.







