GNU Octave Compatibility
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. The reference material consulted while preparing these pages is listed in the section bibliography. |
Written against MATLAB R2026b. GNU Octave is not MathWorks software and is not documented by MathWorks. The Octave facts on this page come from octave.org, from the Octave manual at docs.octave.org/latest (third-party documentation, cited as such), and from running code: the examples throughout this section that Octave accepts were run in a throwaway container of Octave 11.3.0 (gnuoctave/octave:11.3.0), and this page reports what that same installation does for the most common MATLAB features. Octave’s page octave.org announced Octave 11.3.0 on 2026-06-01; on 2026-10-22 the manual at docs.octave.org/latest was still titled version 11.1.0, so a detail of the manual may lag the program. The checked version is 11.3.0 and the container had no Octave Forge packages installed (pkg list printed "no packages installed"), which matters for the table below.
What Octave is
GNU Octave is a free, open-source numerical computing environment whose language is, in its own description, mostly compatible with MATLAB. It runs scripts and functions written in a very similar language, with a command line, plotting through external toolkits, and a package system (Octave Forge). It is a different program, with its own implementation, its own function names where MATLAB’s are newer than its own design, its own bugs, and its own release schedule. "Compatible" is a goal, not a guarantee: code written for MATLAB often runs unchanged, and code that uses what MATLAB added in the last decade often does not.
Reasons to use it with this section: reading and trying the language parts with no licence, running a small script in a CI container or on a teaching machine, and checking that code does not depend on an unneeded MATLAB feature. Reasons not to rely on it: the newer MATLAB features listed below, behaviours that differ in detail, and the absence of MathWorks products.
Source (third-party): GNU Octave, GNU Octave manual
What usually runs unchanged
These parts of MATLAB are common ground, and the section’s examples for them were run in Octave 11.3.0:
-
Numeric arrays, matrix construction, the colon operator,
linspace,reshape,repmat,cat, and N-dimensional arrays. -
Indexing: subscript, linear and logical indexing,
end, deletion with[],find. -
Operators, the relational and logical operators, short-circuit
&&and||, and the precedence rules. -
Control flow:
if,switch,for,while,break,continue,try/catch. -
Cell arrays, structures (
s.field,fieldnames,struct),cellfun,arrayfun. -
Functions in files,
nargin,nargout,varargin,varargout, anonymous functions and function handles. -
Broadcasting, which MATLAB calls implicit expansion. The Octave manual says that since version 3.6.0 it broadcasts automatically, with the same rule as MATLAB’s (dimensions equal, or one of them 1).
-
Linear algebra (
\,inv,det,eig,svd,lu,qr,chol), polynomials (polyfit,polyval),interp1,integral,ode45,fzero,fminsearch,fft,sparseand iterative solvers such aspcg. -
containers.Map(see below),inputParser,validateattributes,jsondecodeandjsonencode,webread. -
Basic 2-D and 3-D plotting with
plot,surfandcontour(needs a graphics toolkit; the container used here has none for display, so no plot was run).
Example: indexing with end, an outer sum that uses broadcasting, an anonymous function and integer saturation, run unchanged in Octave 11.3.0:
A = magic(4);
disp(A(end, :))
a = 1:3; b = (1:3)';
disp(a + b)
f = @(x) x.^2;
disp(f(3))
x = int8(100) + int8(100)
Octave 11.3.0 output:
4 14 15 1 2 3 4 3 4 5 4 5 6 9 x = 127
The last line shows integer saturation, which is the same in MATLAB (int8(200) saturates at 127). MATLAB would also print size headers on some displays (x = int8 127), so do not compare the layout of displayed output between the two programs.
Main differences
| Topic | MATLAB R2026b | Octave 11.3.0 |
|---|---|---|
Double-quoted text |
|
|
The |
Creates a |
|
Comments |
|
|
Increment and compound assignment |
none: write |
|
Logical not and inequality |
|
|
Block terminators |
|
|
Printing |
|
|
Functions in scripts |
Local functions in scripts (R2016b, at the end of the file; anywhere since R2024a) |
A function in a script must be defined before it is used; a script that begins with a function definition needs a leading statement such as |
|
Full support |
Supported in part: the checked class with properties, a constructor and a method worked, but the manual’s chapter on objects describes the older |
Exceptions |
|
|
|
|
The same call worked; the identifier and message were read back |
Display layout |
Size headers such as |
Different spacing ( |
Session tools |
Desktop, Editor, Live Editor, App Designer, Help browser removed in R2024b |
Its own GUI and its own help system |
Source (third-party): Octave manual: Escape Sequences in String Constants, Comments in Octave Programs, Broadcasting, Script Files, Creating a Class, containers.Map
Octave-only syntax is a trap for portable code: a file that uses +=, # comments, printf, ! or endif is not valid MATLAB. If a file must run in both, restrict yourself to the MATLAB forms, which Octave accepts.
Features to check per release
The table runs exist(name) on a list of names in Octave 11.3.0 with no packages installed and reports the result. A nonzero value (2 for a file, 5 for a built-in) means the name exists; 0 means it was not found (the exist value can miss names that live in packages and classes: containers.Map printed 0 by exist but worked when called). For a name that exists, "exists" does not mean "behaves like MATLAB": check the behaviour. The MATLAB release column is where the feature arrived.
| MATLAB feature | Since | Octave 11.3.0 here | Comment |
|---|---|---|---|
|
R2016b, R2017a |
|
|
|
R2013b, R2019a |
not found |
a package may add some |
|
R2016b, R2014b, R2013b |
not found |
|
|
R2022b |
not found |
|
|
R2019b |
the block is not part of the language; |
use |
|
R2020b |
not found |
|
|
R2024b, R2024a |
not found |
|
|
R2011a |
exists |
|
|
R2019b, R2020a, R2014b |
not found |
plotting needs a graphics toolkit in any case |
|
R2013a, R2013a, R2022b |
not found |
Octave has |
|
R2023b, R2016b |
|
|
Live scripts, App Designer |
R2016a, R2016a |
not part of Octave |
plain |
Projects ( |
R2026b, R2024b |
|
see below |
|
R2014b, R2019b |
not found |
|
|
R2013b and later |
not found |
|
The dates that appear in the version baseline of this section are checked there. The others in the "Since" column (for example table and categorical R2013b, datetime R2014b, rng R2011a, live scripts and App Designer R2016a, tiledlayout R2019b, exportgraphics R2020a, readmatrix R2019a) are general knowledge of the release history and were not re-checked against the current documentation. The Octave column is only what the container reported.
Packages: Octave Forge
Octave extends itself with packages maintained by the Octave community and indexed at packages.octave.org (the address redirects to https://gnu-octave.github.io/packages/ on 2026-10-22). The commands are pkg install, pkg load and pkg list; the manual’s chapter on packages describes them. Packages cover areas that MATLAB sells as toolboxes (statistics, signal processing, image processing, control) and also fill language gaps, such as the datatypes package that the string error above points to. They are third-party software with their own licences, and none of this is MATLAB’s package manager: mpminstall, mpackage.json and File Exchange as a repository are MATLAB-only. See Toolboxes and Add-On Products for the MATLAB counterpart.
A strategy for portable code
-
Decide the target first. If MATLAB R2026b is the target, write for it and use Octave only to check what you can. This section’s code does that.
-
Detect Octave when you must. The idiom
isOctave = exist("OCTAVE_VERSION","builtin") ~= 0;returned true in the container (existprinted 5 for the built-in). Use it only to choose between two implementations, never to hide a failure. -
Stay on the common ground listed above: arrays, indexing, cells, structures, plain functions and handles.
-
Avoid the Octave-only syntax (
+=,#,!,endif,printf) in shared files. -
Use single-quoted or double-quoted text consistently, and avoid relying on
stringsemantics or on escapes in double quotes. -
Test both, and treat a difference as a defect to understand, not to paper over.
Pitfalls
-
Assuming that a clean Octave run proves a MATLAB script works. Display layout, error messages and the handling of
classdiffer. -
Assuming that an Octave failure means a MATLAB defect. The feature may be newer than the Octave implementation.
-
Copying Octave-only syntax into a MATLAB file.
x += 1is a syntax error in MATLAB. -
Forgetting that Octave’s manual may lag its program (the 11.1.0 manual and the 11.3.0 program at the time of checking).
Where older books differ
The older books were written for MATLAB 5 to 7 and do not cover Octave. Their MATLAB-only content (GUIDE, the Java desktop, cell publishing) has no Octave counterpart either; the Octave-compatible parts of them (arrays, indexing, control flow, plain functions, numerical methods) are the parts that stayed stable.
See Also
-
How the books were used and the Octave note in the section overview