MATLAB & GNU Octave Module 1 – Start here: MATLAB, Octave and a working setup
MATLAB and GNU Octave: one language, two tools
What MATLAB and GNU Octave share, how their licences, releases and add-ons differ, which to choose for a course or lab, and how code tells them apart.
What you will learn
- Explain what MATLAB and GNU Octave share and how their licences, releases and add-ons differ
- Choose Octave, licensed MATLAB or MATLAB Online (basic) for a given course, lab or research task
- Detect at run time whether code is running in Octave or MATLAB
- Read this track's labels for portable, Octave-only and MATLAB-only features
What you’ll learn
What you will learn
- Explain what MATLAB and GNU Octave share and how their licences, releases and add-ons differ
- Choose Octave, licensed MATLAB or MATLAB Online (basic) for a given course, lab or research task
- Detect at run time whether code is running in Octave or MATLAB
- Read this track's labels for portable, Octave-only and MATLAB-only features
On this page
A twelve-line script that solves for the three currents of a resistor network prints 2.64, 0.60 and −0.56 amperes in MATLAB, and the same three numbers in GNU Octave. One language runs in two programs: MATLAB, a product of MathWorks that needs a licence for full use, and Octave, free software that anyone may install, change and share.
Below you see that script run in Octave, what the two programs share and where their licences, releases and add-ons part ways; you choose one for a course, a lab or a research task, make a script report which program is running it, and learn the labels this track puts on code that works in only one of them.
One script runs unchanged in both programs
Here is the script. R holds the resistances of three loops of a circuit in ohms and V the source voltages in volts.
The backslash in R \ V solves the linear system: A set of linear equations solved together, written in matrix form as A*x = b. In MATLAB and Octave, x = A \ b solves it without forming an inverse. R*I = V for the currents. A for
loop prints each current with fprintf, and max with two outputs returns the largest value and its position:
% same_code_both.m: the three loop currents of a resistor network.
% Resistances in ohms, sources in volts. Runs unchanged in MATLAB and Octave.
R = [ 10 -4 0
-4 12 -6
0 -6 15 ];
V = [24; 0; -12];
I = R \ V; % solve R*I = V for the currents
for k = 1:numel(I)
fprintf('Loop %d: %6.2f A\n', k, I(k));
end
[largest, loop] = max(abs(I));
fprintf('Largest current: %.2f A, in loop %d\n', largest, loop); Octave 11.3 ran it from a terminal. The first line of the output names the Octave that ran it, and each line after
$ is a command you would type yourself:
from session import run, version
version()
run("""
octave-cli same_code_both.m
""") Output
# GNU Octave (aarch64-apple-darwin25.4.0) version 11.3.0 $ octave-cli same_code_both.m Loop 1: 2.64 A Loop 2: 0.60 A Loop 3: -0.56 A Largest current: 2.64 A, in loop 1
Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 same_code_session.py
MATLAB runs the same file without a change, because every line of it belongs to the language the two programs share. The Octave project describes its language as “mostly compatible with Matlab”, and the shared part is large:
- matrices written in brackets, indexing with parentheses, and the colon, as in
1:numel(I); - the arithmetic and comparison operators, among them
\for linear systems and~=for “not equal”; if,for,whileandswitchblocks, each closed withend;- scripts and function files ending in
.m, and comments that start with%; - text in single quotes, cell arrays and structs;
- most built-in functions, from
sumandmaxtoinvandfprintf.
A course written for MATLAB that keeps to this part can be followed in Octave from the first day, and this track teaches this part first.
System of Equations Solver Enter 10x − 4y = 24, −4x + 12y − 6z = 0 and −6y + 15z = −12: the exact answer, 66/25, 3/5 and −14/25, is the 2.64, 0.60 and −0.56 above.Checkpoint
Check: The language both programs share
Licences, releases and add-ons set the two apart
The two programs part ways outside the language. Four differences decide most choices:
| Difference | MATLAB | GNU Octave |
|---|---|---|
| Made by | MathWorks | The Octave Project Developers |
| Licence | Commercial: full use needs a licence | Free software: the GNU GPL, version 3 or later |
| Releases | A year and a letter: R2026a, R2026b | Numbers: 11.1.0, 11.2.0, 11.3.0 |
| Add-ons | Toolboxes and Simulink, products of their own | About 145 packages, installed with pkg |
Octave reports its own licence and version, and lists the packages installed, none in this Homebrew installation:
from session import prompt, version
version()
prompt("about_octave.m") Output
# GNU Octave (aarch64-apple-darwin25.4.0) version 11.3.0 $ octave-cli --quiet octave:1> license() ans = GNU General Public License v3+ octave:2> OCTAVE_VERSION ans = 11.3.0 octave:3> pkg list no packages installed.
Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 about_session.py
Licence. license() answers GNU General Public License v3+. The GNU GPL: The GNU General Public License, the free-software licence of GNU Octave (version 3 or later): anyone may run, study, change and share the program, and copies passed on keep those freedoms. lets anyone
run, study, change and share Octave, and every copy passed on carries the same freedoms. MATLAB is a MathWorks
product: MATLAB Online (basic) costs nothing, and everything beyond it opens with a licence from a school, an employer
or a purchase.
Releases. MathWorks names its releases by year and letter, two a year, such as R2025a, R2025b, R2026a and R2026b. Octave numbers them: 11.1.0 began version 11, and 11.2.0 and 11.3.0 brought fixes. 11.3.0 came four days after 11.2.0 to repair a library version number, and Octave’s news for version 11 tells users of 11.2.0 to update to 11.3.0. Every example in this track ran on Octave 11.3.0.
Add-ons. A MATLAB toolbox: A MathWorks product that adds functions to MATLAB for one field, such as signal processing or control systems. Code that calls its functions runs only where it is installed., such as the Signal Processing Toolbox, adds functions for one
field, and MathWorks lists each toolbox as a product of its own, as it does Simulink, its environment for block-diagram
models. Code that calls a toolbox function runs only where that toolbox is installed. Octave’s add-ons are
Octave package: An add-on for GNU Octave, such as control or signal, listed in the Octave Packages index. pkg list shows the installed packages, and a new installation has none., such as control and signal, listed in the Octave Packages index: pkg list
shows what is installed, and pkg load makes an installed package’s functions available. The Homebrew installation
above has none; the Windows installers from octave.org come with several packages already installed.
Not affiliated
MySmartCoPilot is not affiliated with MathWorks or with the GNU Octave project. MATLAB and Simulink are registered trademarks of The MathWorks, Inc.
Checkpoint
Check: Licences, releases and add-ons
Choosing Octave, licensed MATLAB or MATLAB Online
Three ways of running the language fit three kinds of work:
- GNU Octave on your computer costs nothing and has no limits of time or network. It runs the shared language, so it suits most courses, assignments and research scripts that do not need Simulink or a toolbox.
- MATLAB with a licence is the full product, on the desktop and online. It is the one to use when your school, lab or employer provides a licence, or when the work needs Simulink or a toolbox.
- MATLAB Online (basic) is MATLAB in a web browser, at no cost, with Simulink and nine toolboxes. MathWorks limits it to 20 hours a month and 15 minutes of continuous compute, with 5 GB of storage in MATLAB Drive.
Answer the three questions below for a course, a lab or a project of yours. The table marks the options that fit, with the reason in every cell:
Answer the questions above: the table then marks what fits your case and says why the rest does not.
| Option | Needs no licence | Works without a network | Long runs | Toolboxes and Simulink | Runs MATLAB-only code |
|---|---|---|---|---|---|
| GNU Octave on your computer | Good free software under the GNU GPL, version 3 or later | Good installed on your computer; no account and no network needed | Good runs as long as your computer does | Mixed packages such as control and signal; no Simulink | Mixed the shared language runs; string arrays, tables and newer syntax do not |
| MATLAB with a licence | Poor needs a licence from a school, an employer or a purchase | Good licensed users get the desktop version as well as MATLAB Online | Good desktop runs are limited by your computer; online, 90 minutes at a stretch | Good Simulink and the toolboxes the licence covers | Good it is MATLAB, so MATLAB-only code runs |
| MATLAB Online (basic) | Good no cost, with a MathWorks account | Poor online only, in a web browser | Poor 20 hours a month, and at most 15 minutes of continuous compute | Mixed MATLAB, Simulink and nine toolboxes | Good it is MATLAB, so MATLAB-only code runs |
How the answers decide
- “Does your school, lab or employer give you a MATLAB licence?” No, or I am not sure: rules out MATLAB with a licence. Full MATLAB opens only with a licence linked to your MathWorks account. Without one, the free choices are Octave and the basic plan.
- “Does the work need Simulink, or a toolbox that Octave's packages do not cover?” Yes, it needs one of them: rules out GNU Octave on your computer. Simulink and toolbox functions run only in MATLAB with that product. Octave packages cover some fields, not Simulink.
- “Will you run jobs longer than a few minutes, or work without a network?” Yes, long jobs or no network: rules out MATLAB Online (basic). The basic plan runs in a browser, for 20 hours a month and at most 15 minutes of continuous compute.
- “Does the work need Simulink, or a toolbox that Octave's packages do not cover?” No, the core language is enough and “Will you run jobs longer than a few minutes, or work without a network?” No, short sessions online are fine: adds a caveat to MATLAB Online (basic). Octave covers the shared language with no limits; the basic plan is still a useful second check that code also runs in MATLAB.
In short: Octave for most coursework and scripts, a licensed MATLAB when Simulink, a toolbox or a lab’s licence is part of the work, and the basic plan for short sessions in MATLAB itself, such as checking that your Octave script also runs there.
Planning a long job on the basic plan
A parameter sweep that computes for an hour does not fit MATLAB Online (basic), which MathWorks limits to 15 minutes of continuous compute and 20 hours a month. Run long jobs in Octave or in a licensed MATLAB, and keep the basic plan for short checks.
Checkpoint
Check: Choosing a way to run it
A script can tell which program is running it
Sometimes code must behave differently in the two programs, for example to call a function that only one of them
has. The Octave manual’s test asks whether a built-in function called OCTAVE_VERSION exists. Octave has one and
MATLAB does not:
% which_am_i.m: which program is running this code?
code = exist('OCTAVE_VERSION', 'builtin');
isOctave = code ~= 0;
if isOctave
tool = 'GNU Octave';
else
tool = 'MATLAB';
end
fprintf('exist(''OCTAVE_VERSION'', ''builtin'') returned %d\n', code);
fprintf('Running in %s, version %s\n', tool, version());
fprintf('Built for %s\n', computer()); from session import run, version
version()
run("""
octave-cli which_am_i.m
""") Output
# GNU Octave (aarch64-apple-darwin25.4.0) version 11.3.0
$ octave-cli which_am_i.m
exist('OCTAVE_VERSION', 'builtin') returned 5
Running in GNU Octave, version 11.3.0
Built for aarch64-apple-darwin25.4.0
Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 which_am_i_session.py
In Octave, exist('OCTAVE_VERSION', 'builtin') returned 5, the code exist uses for a built-in function, so the
script took its Octave branch. Step through both branches, with MATLAB’s values taken from MathWorks’ documentation:
The drawing shows the whole scene; its 6 steps are listed below.
Every step as text
- One question. The script first asks whether a built-in function called OCTAVE_VERSION exists. With 'builtin' as its second argument, exist looks at built-in functions only, never at variables or files.
- Octave answers 5. Octave has a built-in function of that name, so exist returns 5, its code for a built-in function. code ~= 0 is true, so isOctave is true.
- The Octave branch. The if block takes its first branch and sets tool to 'GNU Octave'.
- The report. fprintf prints the code, the tool with the version that version() returns, 11.3.0 here, and computer(), the platform the program was built for.
- MATLAB answers 0. MATLAB has no built-in function of that name, and MathWorks documents 0 as the answer for a name that is not found. code ~= 0 is false, so isOctave is false.
- The MATLAB branch. The else branch sets tool to 'MATLAB', and version() returns MATLAB's own version text, which MathWorks' documentation shows as '26.2.0.3341813 (R2026b)'.
MathWorks documents 0 as the answer for a name that is not found, so in MATLAB isOctave is false and the script
reports MATLAB with its own version text. The second argument, 'builtin', makes the test safe: without it, exist
also counts variables and files, so a variable or a file called OCTAVE_VERSION could make MATLAB look like Octave.
Key idea
exist('OCTAVE_VERSION', 'builtin') ~= 0 is true in Octave and false in MATLAB, so one line tells a script which
program runs it; branch on that test, never on a version string.
Checkpoint
Check: Telling Octave from MATLAB in code
Labels mark code that runs in only one program
Octave accepts some code that MATLAB rejects. This script computes the same currents with five Octave-only shortcuts:
a # comment, printf, +=, endfor and endif, and != for “not equal”. It runs in Octave, and Octave can warn
about some of its own extensions:
# octave_only.m: the same currents, written with Octave-only shortcuts.
R = [10 -4 0; -4 12 -6; 0 -6 15];
V = [24; 0; -12];
I = R \ V;
total = 0;
for k = 1:numel(I)
printf("Loop %d: %6.2f A\n", k, I(k));
total += I(k);
endfor
if total != 0
printf("Sum of the loop currents: %.2f A\n", total);
endif % check_extensions.m: runs octave_only.m with Octave's warning about its own
% language extensions switched on, then switches the warning off again.
warning('on', 'Octave:language-extension');
octave_only
warning('off', 'Octave:language-extension'); from session import prompt, run, version
version()
run("""
octave-cli octave_only.m
octave-cli check_extensions.m
""")
prompt("name_value.m")
prompt("quotes.m") Output
# GNU Octave (aarch64-apple-darwin25.4.0) version 11.3.0
$ octave-cli octave_only.m
Loop 1: 2.64 A
Loop 2: 0.60 A
Loop 3: -0.56 A
Sum of the loop currents: 2.68 A
$ octave-cli check_extensions.m
warning: Octave language extension used: += used as operator near line 8 of file octave_only.m
warning: called from
check_extensions at line 4 column 1
warning: Octave language extension used: != used as operator near line 10 of file octave_only.m
warning: called from
check_extensions at line 4 column 1
Loop 1: 2.64 A
Loop 2: 0.60 A
Loop 3: -0.56 A
Sum of the loop currents: 2.68 A
$ octave-cli --quiet
octave:1> parts = strsplit('a,,b', ',', CollapseDelimiters=false);
octave:2> numel(parts)
ans = 3
octave:3> who
Variables visible from the current scope:
CollapseDelimiters ans parts
$ octave-cli --quiet
octave:1> numel("a\tb")
ans = 3
octave:2> numel('a\tb')
ans = 4
Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 extensions_session.py
The first run printed the currents. In the second, the warning Octave:language-extension flagged += and != but
said nothing about the # comment, printf, endfor or endif, so the warning finds some extensions, not all of
them. The third part goes the other way: CollapseDelimiters=false is MATLAB’s way to pass a name-value argument,
but Octave 11.3 read it as an assignment, so who lists a new variable called CollapseDelimiters. The last part
counts characters: inside double quotes Octave turned \t into one tab, so "a\tb" has 3, while 'a\tb' keeps all 4.
This track labels such code in the text and in the titles of examples: Octave-only, MATLAB-only, or Differs when both programs run it with different results:
| Code | Label | In the other program |
|---|---|---|
% note, %{ … %} |
Portable | The same in both |
# note, #{ … #} |
Octave-only | MATLAB comments start with % |
x ~= y, ~ok |
Portable | The same in both |
x != y, !ok |
Octave-only | In MATLAB ! runs an operating-system command |
x += 1, k++ |
Octave-only | MATLAB assigns with = only |
endif, endfor |
Octave-only | MATLAB closes every block with end |
printf("…") |
Octave-only | MATLAB has fprintf |
"a\tb" |
Differs | Octave: text with \t as a tab, 3 characters; MATLAB: a string |
f(x, Name=value) |
MATLAB-only | Octave 11.3: assigns Name, passes only the value |
Code without a label is portable, and examples run on Octave unless their title says otherwise. MATLAB behaviour that these pages describe comes from MathWorks’ documentation.
Trusting Octave's warning to find every extension
warning('on', 'Octave:language-extension') flagged += and != in the run above, but not #, printf, endfor
or endif. Before you hand a script to someone who uses MATLAB, check it against the table, or run it in MATLAB
Online (basic).
Checkpoint
Check: Portable, Octave-only and MATLAB-only code
Practise: which program, which label?
Two tasks wait for the next lesson’s installation. Save which_am_i.m and same_code_both.m, run both, and set
your output beside the recorded runs: only the “Built for” line should name a different platform, and the three
currents must not change. With access to MATLAB or MATLAB Online (basic), run which_am_i.m there as well and see the
else branch report MATLAB.
Five ideas carry this lesson: the shared language, what sets the two programs apart, choosing one, the run-time test and the labels. The practice session below starts with whichever of them your answers show to be weakest, asks one question at a time and explains each answer the moment you give it:
Practice that adapts to you
Practise this lesson
15 questions about 5 ideas of this lesson. Each answer is explained at once, and what you get right is kept in this browser.
Interview questions
Warm-up: what is the difference between MATLAB and GNU Octave?
Both run the same core language: matrices, indexing, operators, control flow, scripts and functions, so a script that
keeps to it, such as one that solves a resistor network with R \ V, runs unchanged in either. MATLAB is a MathWorks
product: full use needs a licence, its add-ons are toolboxes and Simulink, and its releases are named R2026a, R2026b and
so on. Octave is free software under the GNU GPL version 3 or later, its add-ons are packages from the Octave Packages
index, and its releases are numbered, such as 11.3.0. Newer MATLAB features, such as string arrays, tables and
Name=value calls, are missing or behave differently in Octave, and Octave accepts extensions, such as # comments,
+= and endif, that MATLAB rejects. Code can test which one runs it with exist('OCTAVE_VERSION', 'builtin').
Model answers open with any pass: ₹79 for 1 week ($2.99), one payment that never renews.
-
Fresher to mid
You set up the computing for a first-year engineering course of 120 students: Octave on their laptops, a campus MATLAB licence, or MATLAB Online (basic). Which do you choose, and what do you check before deciding?
-
Mid to senior
Your research group has 40 MATLAB scripts and must run them on new laptops that have only GNU Octave. How do you find what breaks, fix it, and keep the scripts working in both programs afterwards?
Key takeaways
- MATLAB and GNU Octave run one shared language, so a script of matrices,
\, loops,%comments andfprintf, such as the three-loop circuit solver, prints the same results in both. - MATLAB is a MathWorks product whose full use needs a licence, named by year and letter (R2026b); Octave is free software under the GNU GPL version 3 or later, numbered by version (11.3.0), with packages instead of toolboxes.
- Octave suits most coursework and scripts, a licensed MATLAB suits work that needs Simulink, a toolbox or a lab’s licence, and MATLAB Online (basic) suits short sessions within its 20 hours a month and 15-minute runs.
exist('OCTAVE_VERSION', 'builtin')returns 5 in Octave and 0 in MATLAB, so a script can branch on it; the'builtin'argument keeps a variable or a file of that name from fooling the test.- This track marks code as Octave-only or MATLAB-only, and Octave’s
Octave:language-extensionwarning finds some of its own extensions, such as+=and!=, but not#comments,printforendif.
Terms in this lesson
- GNU GPL
- The GNU General Public License, the free-software licence of GNU Octave (version 3 or later): anyone may run, study, change and share the program, and copies passed on keep those freedoms.
- linear system
- A set of linear equations solved together, written in matrix form as A*x = b. In MATLAB and Octave, x = A \ b solves it without forming an inverse.
- Octave package
- An add-on for GNU Octave, such as control or signal, listed in the Octave Packages index. pkg list shows the installed packages, and a new installation has none.
- toolbox
- A MathWorks product that adds functions to MATLAB for one field, such as signal processing or control systems. Code that calls its functions runs only where it is installed.
References
- About GNU Octave (The Octave Project Developers)
- GNU Octave news (release announcements) (The Octave Project Developers)
- News for Octave 11 (changes in 11.1.0 to 11.3.0) (The Octave Project Developers)
- GNU Octave manual: Copying (the GNU General Public License) (The Octave Project Developers)
- GNU Octave manual: How to Distinguish Between Octave and Matlab (The Octave Project Developers)
- GNU Octave manual: Status of Variables (exist) (The Octave Project Developers)
- Differences between Octave and Matlab (Octave wiki) (The Octave Project Developers)
- Octave Packages (package index) (The Octave Project Developers)
- GNU Octave manual: Using Packages (pkg load) (The Octave Project Developers)
- Download GNU Octave (packages bundled with the Windows installers) (The Octave Project Developers)
- MATLAB Online Versions (MathWorks)
- R2026b Release Highlights (MathWorks)
- Previous MATLAB and Simulink releases (MathWorks)
- MathWorks trademarks (MathWorks)
- MathWorks products (MathWorks)
- Simulink: a block diagram environment for multidomain models (MathWorks)
- exist: check existence of variable, script, function, folder or class (MathWorks)
- version: version number for MATLAB and libraries (MathWorks)
- MATLAB Operators and Special Characters (MathWorks)
- Add Comments to Code (MathWorks)
- plot (name-value arguments as Name=Value) (MathWorks)
Related tools
Report a problem with this lesson
Kept only in this browser. Your Learn progress