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, sparse and iterative solvers such as pcg.

  • containers.Map (see below), inputParser, validateattributes, jsondecode and jsonencode, webread.

  • Basic 2-D and 3-D plotting with plot, surf and contour (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

"abc" is a string scalar (R2017a and later). class("abc") is string

"abc" is a char array whose backslash escapes are processed ("a\tb" has a tab); 'a\tb' keeps the backslash. The checked class("abc") printed char. The manual describes the escape sequences in double-quoted strings

The string function

Creates a string array

string("abc") failed in the container with "'string' undefined" and a message that the function belongs to the datatypes package from Octave Forge, "which seems not to be installed". Check what your Octave has

Comments

% and %{ ... %}

% and # (and #{ ... #})

Increment and compound assignment

none: write x = x + 2

x += 2, x -= 2, x *= 3 work (the checked run printed 9 after x = 5; x -= 2; x *= 3)

Logical not and inequality

~ and ~=

~, !, ~= and !=

Block terminators

end

end, and also endif, endfor, endwhile, endfunction, end_try_catch

Printing

fprintf, disp

fprintf, disp and printf

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 1; to keep Octave from reading it as a function file

classdef

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 @class folder form; test every feature you use

Exceptions

MException objects with identifier, message, stack

catch ME gave an object whose identifier and message fields work; class(ME) printed struct, not MException

error with identifier

error("id:sub","msg %d",3)

The same call worked; the identifier and message were read back

Display layout

Size headers such as 3×1, 2.0000 + 3.0000i

Different spacing (x = 2 + 3i) and no size headers

Session tools

Desktop, Editor, Live Editor, App Designer, Help browser removed in R2024b

Its own GUI and its own help system

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

string arrays and strings, "text" as string

R2016b, R2017a

string: not found; isstring exists and returned false for "x"

contains, compose and strip were not found; startsWith, endsWith, strjoin, strsplit exist

table, readtable, writetable, readmatrix

R2013b, R2019a

not found

a package may add some

timetable, datetime, duration, categorical

R2016b, R2014b, R2013b

not found

dictionary

R2022b

not found

containers.Map worked

arguments blocks; mustBe* validators

R2019b

the block is not part of the language; mustBePositive exists as a function

use validateattributes or inputParser in portable code

pattern

R2020b

not found

regexp exists

isapprox, createArray

R2024b, R2024a

not found

rng

R2011a

exists

tiledlayout, exportgraphics, histogram

R2019b, R2020a, R2014b

not found

plotting needs a graphics toolkit in any case

matlab.unittest, runtests, buildtool

R2013a, R2013a, R2022b

not found

Octave has test and assert for its own test blocks

readstruct, jsondecode, jsonencode

R2023b, R2016b

readstruct not found; jsondecode and jsonencode exist

Live scripts, App Designer

R2016a, R2016a

not part of Octave

plain .m files with %% sections run as scripts

Projects (matlab.toml), MATLAB Package Manager (mpminstall)

R2026b, R2024b

mpminstall not found; Octave has its own pkg

see below

pyenv, py. calls

R2014b, R2019b

not found

parfeval, backgroundPool, timeit, datastore, codeIssues

R2013b and later

not found

tic and toc exist

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 (exist printed 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 string semantics 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 class differ.

  • 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 += 1 is 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.