Toolboxes
Core MATLAB already covers matrices, plotting, linear algebra, basic statistics, FFTs, ODE solvers and file I/O. Toolboxes are add-on products that extend it for a field: statistics and machine learning, signal or image processing, optimization, control design, deep learning and many more. Each one is a collection of functions (plus apps and documentation) that you license and install separately. Octave's counterpart is the community-maintained packages, most of them listed in the Octave package index (historically "Octave Forge").
Which toolboxes do I have?
ver % MATLAB/Octave version plus every installed toolbox
license('test', 'Statistics_Toolbox') % 1 if a license is available (MATLAB)
which normpdf % the folder tells you which toolbox a function belongs to
matlab.addons.installedAddons % table of installed add-ons (MATLAB)In MATLAB, toolboxes are installed with the Add-On Explorer (Home tab > Add-Ons), which also offers free community contributions from File Exchange. The documentation page of every function shows the product it needs at the top, so check before you rely on a function in code you'll share.
The most common toolboxes
| MATLAB toolbox | What it adds | Typical functions | Octave package |
|---|---|---|---|
| Statistics and Machine Learning | Distributions, hypothesis tests, regression models, clustering, classification | normpdf, ttest2, fitlm, kmeans, fitcsvm, boxplot |
statistics |
| Signal Processing | Filter design, spectra, resampling, peak detection | butter, filtfilt, pwelch, spectrogram, findpeaks |
signal |
| Image Processing | Filtering, morphology, segmentation, region measurements | imfilter, edge, imresize, regionprops |
image |
| Computer Vision | Feature detection, camera calibration, object detection | detectSURFFeatures, estimateCameraParameters |
(none) |
| Optimization | Constrained, linear, quadratic and integer programming, least squares | fmincon, linprog, quadprog, intlinprog, lsqnonlin |
optim (plus core sqp, glpk, qp) |
| Global Optimization | Genetic algorithm, particle swarm, multi-start | ga, particleswarm, GlobalSearch |
(none in common use) |
| Control System | Transfer functions, state space, time and frequency response | tf, ss, step, bode, pid |
control |
| Symbolic Math | Exact algebra and calculus | syms, diff, int, solve |
symbolic (uses Python's SymPy) |
| Curve Fitting | Library of fit models, interactive fitting app | fit, cftool |
optim (leasqr); core polyfit |
| Deep Learning | Neural network layers, training, pretrained models | dlnetwork, trainnet, imagePretrainedNetwork |
(none) |
| Parallel Computing | Parallel loops, clusters, GPU arrays | parfor, parpool, gpuArray |
parallel (different API) |
| Communications | Modulation, channel models, error-correcting codes | qammod, awgn, comm.* objects |
communications |
| Simulink (separate product) | Block-diagram simulation | see Simulink Intro | (none) |
There are dozens more: Financial, Mapping, Text Analytics, Audio, Wavelet, Database, Econometrics, Robotics, Antenna, Bioinformatics, Predictive Maintenance... Universities often have a campus-wide license that includes most of them.
Octave packages
Octave packages are free and installed from inside Octave. A package must be loaded in each session (or in your ~/.octaverc startup file) before its functions exist:
pkg install -forge statistics % download and install from the package index (once)
pkg load statistics % make its functions available in this session
pkg list % installed packages and whether they are loaded
pkg describe -verbose signal % what a package provides
pkg unload statisticsPackages are separate projects with their own maintainers and release cycles. Their function names usually match MATLAB's, but coverage varies: statistics, signal, image, control and symbolic are mature; for deep learning or computer vision there is no real equivalent. On Linux, many packages are also available from the distribution (for example octave-statistics with apt or apk).
Writing code that doesn't depend on a toolbox
A function that is missing simply doesn't exist, so a call fails with an "undefined function" error. exist(name) returns 0 for unknown names, which lets code check first. This playground runs in plain Octave without any packages:
names = {'fminsearch', 'movmean', 'normpdf', 'butter', 'imfilter', 'fmincon', 'tf'};
for k = 1:numel(names)
if exist(names{k}) ~= 0
status = 'available';
else
status = 'missing';
end
fprintf('%-10s %s\n', names{k}, status);
endfminsearch available
movmean available
normpdf missing
butter missing
imfilter missing
fmincon missing
tf missing
In MATLAB with the corresponding toolboxes installed, all seven are available. When a toolbox function is a small piece of maths, it is often easiest to use a core function or write the formula yourself. The next examples replace three toolbox functions with core code that runs everywhere.
Distributions and a t-test without the statistics toolbox
The normal distribution's CDF is a rescaled error function, and the two-sided p-value of Student's t-test is an incomplete beta function, both core functions (erfc, betainc):
normcdf_ = @(x, mu, sigma) 0.5 * erfc(-(x - mu) ./ (sigma * sqrt(2)));
fprintf('P(Z < 1.96) = %.4f\n', normcdf_(1.96, 0, 1));
fprintf('P(90 < IQ < 110) = %.4f\n', normcdf_(110, 100, 15) - normcdf_(90, 100, 15));
% two-sample t-test (equal variances), like ttest2(a, b)
a = [12.1 11.8 12.6 12.4 11.9 12.3 12.0 12.5];
b = [12.9 12.6 13.1 12.7 13.3 12.8 12.5 13.0];
na = numel(a); nb = numel(b); df = na + nb - 2;
sp2 = ((na - 1) * var(a) + (nb - 1) * var(b)) / df; % pooled variance
t = (mean(a) - mean(b)) / sqrt(sp2 * (1/na + 1/nb));
p = betainc(df / (df + t^2), df / 2, 0.5); % two-sided p-value
fprintf('t = %.4f, df = %d, p = %.6f\n', t, df, p);P(Z < 1.96) = 0.9750
P(90 < IQ < 110) = 0.4950
t = -4.7297, df = 14, p = 0.000323
ttest2(a, b) in the toolbox (or the Octave statistics package) gives the same t and p. More on these ideas in Statistics Functions and in the Statistics course.
Linear regression without fitlm
fitlm builds a rich model object, but the coefficients themselves are a least-squares problem, which backslash solves (see Linear Algebra):
x = (1:8)';
y = [2.1 3.9 6.2 7.8 10.1 12.2 13.8 16.1]';
X = [ones(size(x)) x]; % design matrix: intercept + slope
beta = X \ y;
residuals = y - X * beta;
R2 = 1 - sum(residuals.^2) / sum((y - mean(y)).^2);
fprintf('y = %.4f + %.4f x, R^2 = %.4f\n', beta, R2);y = 0.0357 + 1.9976 x, R^2 = 0.9988
Smoothing and peaks without the signal toolbox
movmean and filter are core functions; a peak is simply a sample larger than both neighbours, which a vectorised comparison finds (the toolbox's findpeaks adds options such as minimum height and distance):
sig = [0 1 3 7 4 2 1 3 8 12 9 4 2 1 0 2 5 3 1 0];
smooth = movmean(sig, 3);
fprintf('smoothed: %s\n', sprintf('%.1f ', smooth(1:8)));
inner = 2:numel(sig) - 1;
peaks = inner(sig(inner) > sig(inner - 1) & sig(inner) > sig(inner + 1));
fprintf('peaks at samples %s with heights %s\n', mat2str(peaks), mat2str(sig(peaks)));smoothed: 0.5 1.3 3.7 4.7 4.3 2.3 2.0 4.0
peaks at samples [4 10 17] with heights [7 12 5]
Tip: If you write code for others, list the toolboxes it needs at the top of the README. In MATLAB, the Dependency Analyzer (or
matlab.codetools.requiredFilesAndProducts('myscript.m')) finds them for you.
Learn more: Optimization, Fourier Transform & Signals, Image Processing Basics, Symbolic Math, MATLAB vs Octave.
Test yourself
In Octave, you installed the statistics package but normpdf is still undefined. What is missing?
- A restart of the computer
pkg load statisticsin the current session- A MATLAB license
addpath('statistics')
Which command lists the MATLAB version together with all installed toolboxes?
toolboxverhelp toolboxpkg list
Which core expression replaces normcdf(x) for a standard normal variable?
erf(x)0.5 * erfc(-x / sqrt(2))exp(-x^2/2)1 - x