Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 45 ยท Modeling and Applications

Simulink, Toolboxes and Octave Packages

What Simulink is, how MATLAB toolboxes and Octave packages extend the core, how pkg load works, and how to check licenses honestly, with simulation stand-ins.

The core of MATLAB is a matrix language. Almost everything else you might want, from image filters to neural networks to PLC code generation, arrives as an add-on. Toolboxes extend MATLAB with function libraries. Simulink is a separate product for building simulations by connecting blocks on a canvas instead of writing code. Octave has a similar idea in its packages, which are free and come from a community repository.

This lesson is a map: what exists, what it costs, how to find out what you have, and how to avoid writing a script that only runs on one machine. Simulink, toolboxes and packages cannot run in your browser, so everything marked as MATLAB or Octave here is read-only. The two runnable examples are honest Python stand-ins: they simulate the same kind of block diagram that Simulink would draw, using a hand-written loop and SciPy.

Three ways to extend the core

Toolboxes Paid MATLAB function libraries.
Octave packages Free, installed from Octave Forge.
Simulink Block diagrams that simulate.
1 / 2

Simulink models a dynamic system, something that changes over time, as a diagram. Blocks do the work: a step source, a gain (multiplication), a sum, an integrator, a scope that plots signals. You drag blocks onto a canvas and draw lines between them. Press the run button and Simulink advances time with an ODE solver, much like the ones in Integration, Differentiation and ODEs, and the scope plots what happened.

The classic example is a feedback loop. A reference value is compared with the system's output, the difference is multiplied by a gain, and the result drives the system, which here is a single integrator.

flowchart LR
    R["Step<br/>reference"] --> S(("Sum"))
    S --> K["Gain K"]
    K --> I["Integrator<br/>1/s"]
    I --> Y["Scope<br/>output y"]
    I -->|"feedback"| S

A feedback loop: the output is subtracted from the reference, scaled by K, and integrated.

Simulink shines when the system has many interacting parts (motors, sensors, controllers, state machines) and when you want to generate code for a microcontroller or test a controller against a virtual plant. Models are saved in .slx files. You can also drive Simulink from a script:

MATLAB
open_system('myModel')              % open a saved model
out = sim('myModel', 'StopTime', '10');   % run it for 10 seconds
plot(out.tout, out.yout)            % results come back as ordinary arrays
set_param('myModel/Gain', 'Gain', '3')    % change a block parameter by name

Simulink is a separate paid product that needs MATLAB, and add-ons such as Stateflow (state machines), Simscape (physical components) or Simulink Coder (code generation) are licensed on top. Octave has no Simulink equivalent. The nearest free options are writing the equations as ODEs with ode45 or lsode, or using the control package for transfer-function work. Projects like Scilab/Xcos or OpenModelica provide block-diagram tools if you want a free diagram editor, but they are separate programs, not part of Octave.

Python The feedback loop, simulated block by block

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A larger gain makes the loop settle faster: the time constant of this loop is 1/K seconds. Simulink does the same calculation, only with a smarter solver than the fixed Euler step used here, and it draws the diagram for you. Real models add a second integrator (for example position and velocity of a mass on a spring), noise, saturation limits and a controller.

Python A mass on a spring, as two integrators

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

MATLAB toolboxes

A toolbox is a collection of functions, apps and examples for one field. The core MATLAB license gives you matrix math, plotting, file I/O, and basic statistics and ODE solvers. Everything below needs its own license:

Toolbox What it adds
Statistics and Machine Learning Distributions, hypothesis tests, regression, classification
Optimization fmincon, linprog, quadprog, lsqnonlin
Signal Processing Filter design, spectrograms, windows
Image Processing imshow, edge, imfilter, segmentation
Symbolic Math syms, solve, exact calculus
Curve Fitting fit, fitting app, many model types
Parallel Computing parfor, parfeval, GPU arrays
Control System Transfer functions, Bode and root-locus plots
Deep Learning Neural network layers and training

Some function names that look like core are not. fzero, fminsearch, ode45, integral, polyfit and trapz are core. fmincon, normpdf, rgb2gray, butter and lsqcurvefit are toolbox functions.

How to find out what you have, and whether a script will work elsewhere:

MATLAB
ver                                  % list MATLAB and installed toolboxes
license('test', 'Statistics_Toolbox')   % 1 if you are licensed for it
which normpdf                        % shows the file and the toolbox that owns it
exist('normpdf')                     % 2 or 6 if it is found, 0 if not

matlab.addons.toolbox.installedToolboxes returns the same list as a table in newer releases. The Add-On Explorer (the Add-Ons button on the Home tab) installs both official add-ons and free community code from File Exchange. Community files are simply code someone else wrote: read them before running them, and note that they may need a particular MATLAB version.

Octave packages

Octave's equivalent is the package system. Packages live on Octave Forge and are free and open source. You install them once and then load them in every session in which you need them:

MATLAB
pkg list                          % installed packages (a star marks the loaded ones)
pkg install -forge statistics     % download and install; needs an internet connection
pkg load statistics               % make its functions available in this session
pkg unload statistics             % remove them again
pkg describe -verbose statistics  % what the package contains

Two details catch people out. First, installing is not loading: after pkg install you still need pkg load at the top of each script. Second, some packages need a compiler or extra system libraries, and some need other packages first, so an install can fail on a machine without the right tools; read the error message, which usually names what is missing. The popular packages are statistics, signal, image, control, symbolic (needs Python and SymPy), optim, io (spreadsheet and data import) and parallel.

For code that must run in both MATLAB and Octave, test for Octave instead of assuming:

MATLAB
isOctave = exist('OCTAVE_VERSION', 'builtin') ~= 0;
if isOctave
    pkg load statistics
end

Octave's package versions evolve independently of the toolboxes, and function behavior is similar but not identical. If a script depends on an obscure option, check it on both.

Licensing, honestly

MATLAB, Simulink and every toolbox are commercial software. Universities and companies often have campus or network licenses that include a long list of toolboxes, while an individual license usually includes only the products you bought. Student and home licenses exist but may restrict use to learning, and MATLAB Online and the free browser version have limits on time and toolboxes. A script that uses a toolbox you do not have fails with an error such as Undefined function 'normpdf' for input arguments of type 'double' or a license checkout failure. That means a missing function, not a typo.

Practical advice: share scripts with a comment at the top listing the toolboxes they need; check what a toolbox function really does before depending on it, because many have a core replacement (normpdf(x, 0, 1) is just exp(-x.^2/2)/sqrt(2*pi)); and read the license terms of your own installation. The Octave route has no license cost, but you accept a smaller set of features and some compatibility gaps. This tutorial's lessons mark every toolbox function, so you can choose.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is Simulink mainly used for?

    Simulink models systems over time as block diagrams and runs them with a solver. Plots and file I/O are core MATLAB.
  2. 2. Which of these functions is part of core MATLAB, not a toolbox?

    fzero is core. fmincon belongs to the Optimization Toolbox, rgb2gray to Image Processing and normpdf to Statistics and Machine Learning.
  3. 3. You ran pkg install -forge statistics in Octave. Why does a script still fail on normpdf?

    Installing puts the package on disk. Loading makes its functions visible, and that must happen in every session.
  4. 4. How can a script tell whether it is running in Octave?

    OCTAVE_VERSION is a built-in function that exists only in Octave. This is the usual portability check.
  5. 5. What is a good habit when sharing a script that uses toolbox functions?

    Others may not have the same licenses. A short list of requirements lets them check before they run it.

Summary

  • Simulink builds simulations from blocks and a solver; it is a separate paid product, and Octave has no direct equivalent.
  • Toolboxes are paid function libraries; ver, license('test', ...), which and exist show what you have.
  • Core functions such as fzero, ode45, polyfit and trapz need no toolbox; fmincon, rgb2gray and normpdf do.
  • Octave packages are free: pkg install -forge name once, pkg load name in every session.
  • Write portable code by testing exist('OCTAVE_VERSION', 'builtin') and listing required toolboxes at the top of a script.
  • Many toolbox functions have short core replacements, so check before you depend on a license.

Next: Project: Fit a Model to Data.