MATLAB is an incredibly powerful tool for engineers, not just for number crunching solutions to specific problems, but as an aid to creativity. MATLAB power users sometimes talk about it feeling almost like an extension of their brain. Even for a dyed in the wool C programmer like me, it’s really useful to sketch out algorithms in MATLAB before implementing them in C. MATLAB’s notation for manipulating arrays is wonderfully concise and the ability to visualise data sets at the drop of a hat using its graphing tools really helps the creative process.
The main problem with MATLAB is that its a proprietary platform and even the student version comes with a hefty price tag. This is where Octave comes in – it’s basically an open source implementation of the MATLAB language. There are other free alternatives, like Scilab and FreeMat, but Octave seems to be the one that’s most consistent with MATLAB. Provided that you steer clear of non-compatible toolboxes, your Octave M-files should run fine in MATLAB.
Installing Octave on Windows
Unfortunately, it’s not immediately obvious how to install Octave on Windows. Visitors to the Octave home page need to do a bit of detective work to find their way to the correct binary executable installer for Windows. Personally, I think it would be really great if the correct download link was given pride of place on the Octave home page. I can’t help wondering whether 9 out of every 10 people who go looking for Octave end up abandoning the idea because they’re not quite sure which version to try.
Fortunately, once you know what to do, installing Octave on Windows is fast and straightforward and really is worth the effort. I don’t have MATLAB installed on my laptop at all anymore – I just use Octave.
The exact file to download is “Octave 3.6.4 for Windows Microsoft Visual Studio” which is one of the versions provided on Octave Forge. Here’s the link:
- octave-3.6.4-vs2010-setup.exe (68.2 MB)
Run the installer and accept the default installation location (C:\software\Octave-3.6.4\) and other default options, as shown in the following sequence of screen shots:
Now just wait while the installation takes place…
Fix for Windows 8
If you’re running Windows 8, you’ll probably run into the same problem I did when I first ran Octave – the command prompt was missing from the command window, as shown below:
If so, you just need to do one small fix on the newly installed Octave to get things working. As a workaround for a gnulib Windows 8 compatibility bug, you need to add some command line switches to the octave.exe desktop shortcut: Right click the Octave desktop shortcut and click on “Properties”. Add the text "-i --line-editing" to the end of the Target field. Assuming you installed Octave in the default location (“C:\Software\Octave-3.6.4\”), the complete Target line will be as follows:
C:\Software\Octave-3.6.4\bin\octave-3.6.4.exe -i --line-editing
Here’s how it looked on my laptop:
Now just click OK and you’re ready to start using Octave. Double click on the desktop shortcut to start it up. Here’s how it looks when I open it on my laptop.
As you can see, it looks very different from MATLAB. However, we can type the same commands in Octave that we would use in MATLAB. In the following example, I’ll create an array of time values, use it to generate a sinusoidal function, and then plot the sinusoid in a figure window.
Just like in MATLAB, a sequence of commands can be stored in an M-file. However, you’ll need to use an external text editor. The one I strongly recommend is Notepad++ which is free to download from http://notepad-plus-plus.org/. Notepad++ is an incredibly useful text editor which can be used for all kinds of programming tasks (editing M-files is just one thing it’s good at).
Here’s an example of writing an M-file in Notepad++:
Once I saved my M-file, I ran it in the Octave command window as shown below:
Useful Octave commands
In the final screen shot above, you can see some useful commands for moving between different folders.
- The pwd command displays the “present working directory” – i.e. the full path of the folder you’re currently in. If you’re trying to run an M-file, pwd should display the name of the folder that contains your M-file.
- The cd command is used to “change directory” – i.e. move to a different folder inside the one you’re in.
- The command “cd ..” leaves the current folder and returns you to the one that contains it.
- The clc command clears the command window.