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)

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:

test1.m

Tip

  • 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.

About the Author

Thomas Bourdin began writing professionally in 2010. He writes for various websites, where his interests include science, computers and music. He holds a Bachelor of Science degree in physics with a minor in mathematics from the University of Saskatchewan and a Master of Science in physics from Ryerson University.

Photo Credits

  • photo_camera Patrick Ryan/Lifesize/Getty Images