Toolboxes, Simulink and Modern MATLAB Features

This module surveys what lies beyond core MATLAB.

Concept

This module surveys what lies beyond core MATLAB. *These features require MATLAB and/or toolboxes and are not run in this course.*

butter, filtfilt, designfilt, pwelch, spectrogram, xcorr

tf, ss, pid, step, bode, margin, pidtune fmincon, linprog, quadprog, lsqcurvefit, optimproblem ga, particleswarm, GlobalSearch Statistics and Machine Learning distributions, hypothesis tests, fitlm, classification, clustering networks, training, deployment exact algebra, calculus and equation solving with syms fit, interactive fitting app Image Processing / Computer Vision filtering, segmentation, feature detection

CAN/CAN FD/XCP communication, DBC files, MDF logs parfor, parfeval, GPU arrays

A graphical environment for modelling dynamic systems as block diagrams, with continuous and discrete solvers, Stateflow state machines, physical modelling (Simscape) and code generation (Embedded Coder, AUTOSAR). Typical automotive workflow: requirements → Simulink model → model-in-the-loop tests → generated C code → software-in-the-loop → hardware-in-the-loop → vehicle.

Modern Language Features string arrays, "..." Supported in Octave too Local functions in scripts At the end of the script arguments blocks Declarative input validation table, timetable Faster, typed maps Live Scripts, App Designer Documents and GUIs exportgraphics, tiledlayout MATLAB and Other Languages

MATLAB can call Python (py.module.function), C/C++ (MEX, loadlibrary), Java and .NET; MATLAB Engine APIs let Python/C++ programs call MATLAB; MATLAB Coder converts MATLAB code to C/C++. Free alternatives and complements include GNU Octave (used for this course's outputs), Python with NumPy/SciPy/Matplotlib, and Julia.

% Symbolic Math Toolbox - not run in this course
syms x
f = x^3 - 6*x^2 + 11*x - 6;
factor(f)                 % (x - 1)*(x - 2)*(x - 3)
diff(sin(x)^2, x)         % 2*cos(x)*sin(x)
int(exp(-x), x, 0, Inf)   % 1
solve(x^2 + 2*x - 3 == 0, x)
% MATLAB R2019b+ - not run in this course
function y = scale(raw, factor, offset)
    arguments
        raw double {mustBeNonnegative}
        factor (1,1) double = 1
        offset (1,1) double = 0
    end
    y = raw * factor + offset;
end

Why It Matters

Knowing which tool solves which problem saves weeks — and job descriptions for control, signal-processing and automotive roles list these toolboxes explicitly.

Example

Toolbox examples are not executed in this course. To check what your installation provides, run ver (MATLAB lists installed toolboxes; Octave lists installed packages).

Expected Result

Not applicable — this module is a guided tour.

Common Mistakes

Writing core code that silently depends on a toolbox your colleagues don't have (check with license('test', ...) or matlab.codetools.requiredFilesAndProducts).

Using string arrays in code that must also run on older MATLAB versions or Octave.

Rebuilding in core MATLAB what a licensed toolbox already does reliably.

Best Practices

Document required toolboxes and minimum MATLAB release at the top of shared code.

Use Simulink for dynamic systems that will become embedded code; use scripts for analysis.

Prefer core functions for portable utilities.

Interview Relevance

Medium–high for industry roles: "which toolboxes have you used?", "what is Simulink used for?", "what is Embedded Coder?", "what are string arrays and how do they differ from char arrays?".

Practice Questions

List the toolboxes installed on your MATLAB with ver.

Rewrite a function's nargin/validateattributes checks as an arguments block (MATLAB R2019b+).

Convert a cell array of char vectors to a string array and back (MATLAB).

Sketch the Simulink model of the PI speed controller from Module 26.

Quick Quiz

Q1. (Multiple choice) Which product generates embedded C code from Simulink models? A) MATLAB Compiler B) Embedded Coder C) App Designer D) Live Editor Answer: B.

Q2. (True/False) "abc" and 'abc' create the same class in MATLAB.

Answer: False. "abc" is a string, 'abc' a char vector.

Q3. (Predict the output) (MATLAB) class(["a" "b"] + "x")

Answer: string — string arrays concatenate with +.

Q4. (Find the bug) A shared script calls butter and fails on a colleague's machine with "Undefined function".

Answer: butter is in the Signal Processing Toolbox, which the colleague lacks; document or remove the toolbox dependency.

Coding Challenge

Without the Signal Processing Toolbox, implement a second-order moving-average smoother by applying filter(ones(1,5)/5, 1, x) twice to a noisy ramp, and compare the standard deviation of the error from the ideal ramp before and after smoothing (ignoring the start-up samples).

rng(7);
t = 0:0.01:2;
ideal = 3 * t;
x = ideal + 0.2 * randn(size(t));
y = filter(ones(1, 5) / 5, 1, filter(ones(1, 5) / 5, 1, x));
delay = 4;                                      % two filters of delay 2 samples each
err = y(delay + 11:end) - ideal(11:end - delay);
fprintf('error std: raw %.4f, smoothed %.4f\n', std(x(11:end) - ideal(11:end)), std(err))