Octave

From UCT EE Wiki
Revision as of 12:46, 8 February 2020 by CRNKEE002 (talk | contribs)
Jump to navigation Jump to search

Octave is an open source MATLAB-like application. More information can be found at the Octave website.

Octave-logo.png

Installation

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

The Octave IDE on Start Up (Windows)

Path

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

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

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

Writing Functions

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

Packages

Octave Forge allows you to install packages to use within Octave.

pkg list 
Lists installed packages
pkg install -forge <pkg-name> 
Install a package