Octave Cheatsheet

Working with files

Load CSV file into a matrix. This command loads file ex2data.txt and stores its contents in a variable named ex2data:

Matrices and Vectors

Appending to a vector (does not work on matrices as this would break the rectangular shape):

a = [1; 2; 3];
a(end + 1) = 4;


Create empty figure:

Plot XY diagram using “+” markers in black:

Plot multiple datasets in one XY diagram:


Create a random permutation of the integers 1 to 10:

The same function can be used for drawing without replacement, e.g., out of a number of items 1,2,…,10 take five distinct elements:

Utility functions

Change default prompt (PS1):

Change/check working directory:

What variables are currently defined/visible:

Continue command in next line by typing three dots

Reading user input from the shell:

x = input(“Please enter the value of x: “);


  • Commands can be concatenated with a comma (produce output) or semicolon (hide output).
  • Reverse i search works just like for the Bash


  • [1] Octave documentation

Leave a Reply