Octave

From UCT EE Wiki
Jump to navigation Jump to search

Octave is an open source, MATLAB-like, numerical computing application (see Category:Numerical Computing). More information can be found at the Octave website.

Octave-logo.png

Installation[edit]

For full details on how to use Octave, visit An Introduction to Octave. The full Octave Documentation is also available online.

If you're following a guide and get a "function undefined" error from a built-in function, the function may have been deprecated. For a list of deprecated functions, visit Octave Obsolete Functions.

The IDE[edit]

The Octave IDE on Start Up (Windows)

Path[edit]

When a function is called, Octave searches a list of directories for a file that contains the function declaration. This list of directories is known as the load path. By default the load path contains a list of directories distributed with Octave plus the current working directory. To see your current load path, you can run path() in the Command Window.

If you are working on your own project in a separate directory, you either need to ensure Octave is in that current working directory by using the "Current Working Directory" drop down at the top left of the window, or manually add it to your path by running addpath("<path>") in the Command Window.

Command Window[edit]

The Command Window is what is usually shown on start up. Here you can call your script files that are on the path, or run some simple commands.

Editor[edit]

The editor is where you can create your own scripts. To run your script, you can press the F5 key.

Changing the editor[edit]

In OCTAVE you can type the edit command in order to open up the default editor. Generally, this editor is emacs - which many people don't like. How do you change the editor that opens when you type in edit at the command line?

For me, it doesn't seem to work if I type in something like EDITOR("gedit") at the Octave command line to override the default of loading emacs with loading up the more friendly gedit instead. If I do this EDITOR command and later type in edit test.m, then it still uses emacs.

So what I do instead is run the command system("gedit test.m") to open the file. You could write an .m file, e.g. called myed.m, to which you pass a parameter of the filename to edit, and it simply calls the above system command to edit the given filename.

If anyone has a better solution, please post it to this thread.


Writing Functions[edit]

If you would like to create your own functions to run in other scripts or from the command window, you can run through the following steps:

  1. Create a file myfunction.m, where "myfunction" is the name of the function you'd like to call.
  2. In it, write your code, using the code below as a template:
    function result = myfunction(varA, varB)
        # Perform any logic you'd like done
        result = varA + varB;
    endfunction
    
  3. Be sure that the location of the .m file is on your path, either through adding it manually, or ensuring you are in that location in the IDE.

Packages[edit]

Octave Forge allows you to install packages to use within Octave. For a more in-depth description of forge and Octave packages, visit the Octave Forge Wiki.

pkg list 
Lists installed packages
pkg install -forge <pkg-name> 
Install a package
pkg load <pkg-name> 
loads a package in to the current Octave session

Useful Packages[edit]

The following is a list of packages considered useful by staff, students and researchers:

communications 
The communications package provides digital communications functions for use with Octave. The functions provided by the communications package include creation of signals and noise, channel modeling and equalization, block and convolutional coding, and modulation and demodulation.
control 
The control package provides Computer-Aided Control System Design (CACSD) Tools for GNU Octave, based on the proven SLICOT Library.
image 
The Octave-forge Image package provides functions for processing images. The package also provides functions for feature extraction, image statistics, spatial and geometric transformations, morphological operations, linear filtering, and much more.
mexopencv 
This mexopencv package provides matlab mex functions that interface a hundred of OpenCV APIs.
parallel 
The Parallel execution package provides utilities to work with clusters, but also functions to parallelize work among cores of a single machine. Note that there may be some issues with this package on Windows.
signal 
The signal package provides signal processing algorithms for use with Octave. The functions provided by the signal package include creation of waveforms, FIR and IIR filter design, spectral analysis, Fourier and other transforms, window functions, and resampling and rate changing. There are also some wavelet functions included, because there is no separate wavelet package, at least for now.
sockets 
The Sockets Package can be used to communicate over network with TCP/IP.