Main»Octave Matlab Notes

Octave Matlab Notes

Octave

Category: Software

On this page... (hide)

  1. 1. Octave Documentation:
  2. 2. Windows
  3. 3. Macintosh
    1. 3.1 Installation
    2. 3.2 Setup
    3. 3.3 Using Octave

Jan 2011 update:

  • A couple of updates for new (10.5.8 and higher) versions of Mac OS:
    • In case you need an X11 update, you can get it here: http://xquartz.macosforge.org/trac/wiki/X112.5.3
    • Gnuplot needs a tweak to work with OS 10.6 Snow Leopard and late versions of 10.5.8 (see note on Octave download page). Here (attached zip file) is a version that should work. Download this zip file, unzip it, and drag it into your Applications folder. Continue with the rest of the installation and setup instructions as below.
    • It is recommended that Mac users install 4 things: Octave, Gnuplot, Aquaterm, Aquamacs (see details below). If "bike_example.m" plots, you're all set.
  • Octave Workshop seems not to be working with Windows beyond XP. A better alternative might be qtoctave: http://qtoctave.wordpress.com/what-is-qtoctave/

Octave is a free, open-source alternative to Matlab that uses a virtually identical syntax so that many Matlab programs will immediately run in Octave. You can access Matlab for free on the Unix servers at Stanford, but it can get rather slow. For Windows users, the student Matlab edition at the bookstore is so nice that the motivation to use Octave is not as strong, especially if you will be using Matlab frequently in other courses. Mac users are still stuck with the X11 port of Matlab, which is a bit clunky, so Octave looks better in comparison.

1.  Octave Documentation:

The Octave manual is at http://www.gnu.org/software/octave/doc/interpreter/ Also, enough people around the world are using it that you can find help on many topics by Googling

 "Octave ????" where ???? is a description of what you want to know.

Some basic Matlab tutorials (which also work for Octave) are on the ME112 Coursework site.

2.  Windows

Jan2011 I'm no longer recommending Octave Workshop. You could try qtoctave instead: http://qtoctave.wordpress.com/what-is-qtoctave/

I still think the regular student Matlab for Windows is hard to beat. For more information about how to load Octave in Windows see Octave for Windows

Jan 2010: It looks like the simplest Windows solution may be Octave Workshop, which integrates the graphics and basic Octave engine. This is a single installation. After you install it, try loading the bike_example.m file (download the link with "save as" and rename to get rid of the ".txt" extension) into Octave Workshop.

3.  Macintosh

3.1  Installation

Before you start: Compared to Matlab, installation is a bit fiddly (see below) but it runs pretty much like Matlab once installed. You need to be willing to run the Terminal utility (in Applications/Utilities) and carefully type some commands at the Unix command line level. Follow the instructions below step by step.

Importantly, you need to install four interacting programs to make everything work: (i) the main Octave engine, (ii) Gnuplot for plotting, (iii) Aquaterm for displaying plots in a Mac-friendly way and (iv) some nice "Matlab-aware" editor like Aquamacs for composing your programs and snippets of code.

1. Get the program from http://octave.sourceforge.net/ There are versions for Windows, Mac and Linux. On Macs, pick either the Intel (i386) or older PPC version, as needed. Launch the ".dmg" disk image and install the main Octave program (drag its icon in the Applications folder icon, as the install program suggests). At this point, the basic Octave engine should run. But don't close the disk image yet because....

2. For plotting, you'll also need the GNU Plot program. On Macs, you'll find a Mac version of Gnuplot inside the Extras folder of the Octave .dmg disk image. Install it unless you have a fairly new version of Mac OS, in which case use the version attached above.

3. Gnuplot wants a terminal for displaying graphics. On Macs, this means you'll probably want to install Aquaterm. Install it in your Applications folder, using the same procedure as for Octave and Gnuplot.

4. You will also want a programming text editor. See Using Octave below for a couple of options. I like Aquamacs.

If you have an older Mac... - You need X11 installed for Gnuplot to work. On new Macs, it's installed by default. Look in Applications/Utilities to see if you have it. On older Macs you can install it (it's an optional install) from your System Software DVD. If you can't find your DVD, you can try this link for Windows 10.5: how to install X11 without DVD. FYI, X11 is the Unix windowing environment for Macs. (By the way, you also need X11 to run Matlab on Macs.) If you are still running 10.4, you will need your DVD or to find X11 somewhere...

3.2  Setup

On Macs and Linux, Octave runs at the Terminal command line. On Macs, it is easiest to get started by launching the Terminal utility under Applications/Utilities. You'll want to create a text file, if it doesn't already exist, called .bash_profile in your home directory. (Because it is preceded by "." it will normally be invisible. To see such files. use the Terminal directory command: ls -la ). Make sure you are in your Home directory (the Terminal command cd will always take you there.)

If you are not familiar with emacs or other command line editor, the easiest way to do things is probably to download the following file: Attach:bash_profile.txt In your browser, use Save-as to save this file into your home directory (the top-level folder that has Documents, Library, Pictures, Desktop, etc. Then, using the Terminal program type:

  • cp bash_profile.txt .bash_profile <enter> (This will copy the contents of the text file into a hidden file called ".bash_profile" in your home directory.)
  • Finally, type source .bash_profile <enter> to make sure your Mac processes the good stuff you just added.

OK, if you now type octave at the terminal command line, it should run. (Type "quit" in octave, to exit).

Note: As an alternative, if you are familiar with the open source Eclipse software development environment you may prefer to use the Eclipse Octave plugin: Octclipse.

A good test of whether all the Gnuplot, Aquaterm graphics stuff is working is to see what happens if you load bike_example.m into Octave. Download the bike_example.m link using "save as" in your browser and rename it to get rid of the ".txt" extension). You load it into Octave by simply typing "bike_example" (without the ".m") in Octave. But you have to have it in the same directory (see below).

3.3  Using Octave

If you are not using Eclipse, the way you will usually use Octave is to open two windows, one for writing code and one for running it, popping back and forth to copy and paste snippets, functions, etc. The simplest way is to use the Terminal utility to run octave and a standard text editor to write and modify programs. I like Aquamacs because it knows about ".m" files with pretty formatting (and supports emacs key shortcuts) but any plain text editor will do. A popular free text editor for Mac is Text Wrangler.

You might like to drag the Terminal utility into your Dock so you don't have to hunt for it in Applications/Utilities every time!

Directories: One thing you'll want to set up correctly (and this applies for Matlab too) is that your Octave program and the files you read and write are all working in the same directory. When you open the Terminal program, you are usually in your Home directory. To get somewhere else use the cd command. For example: cd Documents/me112. Do this first and then type 'octave'. Now octave will be looking in this directory for your various ".m" files and data files.

  • If you are ever unsure about where Octave thinks it is working, type the command 'pwd' (print working directory) in Octave.
  • If you want to change directories to somewhere else, the 'cd' command works within Octave too.
  • The 'ls' (list directory) command also works, so you can see what's in the directory where you currently are.

For example:

 octave-3.0.3:6> cd Documents
 octave-3.0.3:7> pwd
 ans = /Users/mrc/Documents