How to Run MATLAB Code in Octave

By Thomas Bourdin

Updated September 28, 2017

Items you will need

  • Computer with GNU Octave installed

  • .m file (Matlab program file)

GNU Octave is capable of executing many numerical and scientific calculations.
i Patrick Ryan/Lifesize/Getty Images

Matlab is a numerical computing software program that was created by computer scientist Cleve Moler. Matlab is well known for its ability to handle matrix operations, as well as the ease of use of the programming language. However, the cost for Matlab often can be prohibitive, and a user may want to improve on a built-in Matlab program. GNU Octave is an open-source alternative to Matlab that has similar capabilities and a similar program language syntax. Because of this, Matlab code often can be executed using Octave.

Open the GNU Octave program on your computer. This generally is done using a command terminal.

Navigate to the specific directory where the Matlab program you wish to run is located. For example, in Linux, you can navigate to the directory where the file is located by using a command similar to

cd home/matlab/files/

where "cd" is the change directory command and the specific file is contained in files.

Run the Matlab program on your computer by typing the command in the terminal. For example, to run the file test1.m in Octave, you would type:



There may be a difference in syntax between a Matlab file and an Octave file. Ensure you have corrected any differences between the code of the two programs, otherwise you will encounter errors.