Introduction to Octave – Basics Operations

GNU Octave is a high-level programming language mostly used for numerical computations and algorithms.

In this series we will learn the necessary programming required for computational neuroscience, using Octave – as well as Matlab.

Elementry operations

5 + 6

ans = 11

3 - 2

ans = 1

5 * 8

ans = 40

1/2

ans = 0.50000

2^6 <em>(to the power)</em>

ans = 64

Logical operations

1 == 2 <em>(is equal to)</em>

ans = 0 <em>(false)</em>

1 ~= 2  <em>(not equals, note that we use the squiggly sign)</em>

ans = 1 <em>(true)</em>

1 &amp;&amp; 0 <em>(AND)</em>

ans = 0 <em>(false)</em>

1 || 0 <em>(OR, using pipes)</em>

ans = 1 <em>(true)</em>

xor(1,0) <em>(exclusive or)</em>

ans = 1 <em>(true)</em>

Variables

To assign a value to a variable, you just denote:

a = 3

b = 'hi'

c = (3&gt;=1)

To suppress the output, success the line with a semi-colon

a = pi;

To print out the value, just use the variable name, or for more complex printing use:

disp(a)

Example:

disp(sprintf('2 decimals: %0.2f', a))