Difference between revisions of "Octave"

From ArchWiki
Jump to: navigation, search
(Octave-Forge: packaging)
(Plotting: default backend as of 4.2.1 is Qt)
 
(38 intermediate revisions by 18 users not shown)
Line 1: Line 1:
 
[[Category:Mathematics and science]]
 
[[Category:Mathematics and science]]
{{Article summary start}}
+
[[ja:Octave]]
{{Article summary text|This article contains information about the installation, configuration and use of GNU Octave.}}
+
{{Related articles start}}
{{Article summary heading|Related}}
+
{{Related|Matlab}}
{{Article summary wiki|Matlab}}
+
{{Related|Sage-mathematics}}
{{Article summary wiki|Sage-mathematics}}
+
{{Related|Mathematica}}
{{Article summary wiki|Mathematica}}
+
{{Related articles end}}
{{Article summary end}}
+
 
 
From the [http://www.gnu.org/software/octave/ official website]:
 
From the [http://www.gnu.org/software/octave/ official website]:
  
Line 12: Line 12:
  
 
== Installation ==
 
== Installation ==
Octave can be [[Pacman|installed]] with the package {{Pkg|octave}}, available in the [[official repositories]].
+
[[Install]] the {{Pkg|octave}} package.
 +
 
 +
Run the GUI app with ''octave'' or the CLI app with ''octave-cli''.
  
== Octave-Forge ==
+
=== Alternative graphical interfaces ===
  
Octave provides a set of packages, similar to Matlab's Toolboxes, through [http://octave.sourceforge.net/index.html Octave-Forge]. Some of these packages may be found in the AUR ([https://aur.archlinux.org/packages.php?O=0&K=octave-&do_Search=Go search packages]). A non-exhaustive list:
+
The default ''octave'' GUI is included in the {{Pkg|octave}} package. Alternatively, you can use one of the following unofficial GUIs:
* {{App|Image|Provides functions for processing images.|http://octave.sourceforge.net/image/index.html|{{AUR|octave-image}}}}
+
* {{App|Cantor|A graphical user interface that delegates its mathematical operations to one of several back ends (Scilab, Maxima, Octave and others).|http://edu.kde.org/cantor/|{{Pkg|cantor}}}}
* {{App|Statistics|Provides additional statistical functions.|http://octave.sourceforge.net/statistics/index.html|{{AUR|octave-statistics}}}}
+
* {{App|QtOctave|A Qt frontend for Octave.|https://forja.rediris.es/projects/csl-qtoctave/|{{AUR|qtoctave}}{{Broken package link|package not found}}}}
* {{App|IO|Provides input and output in external formats such as XML, CSV or XLS.|http://octave.sourceforge.net/io/index.html|{{AUR|octave-io}}}}
 
* {{App|Signal|Provides functions for processing images|http://octave.sourceforge.net/image/index.html|{{AUR|octave-signal}}}}
 
* {{App|Multicore|Provides functions for parallel processing on multiple cores.|http://octave.sourceforge.net/multicore/index.html|{{AUR|octave-multicore}}}}
 
  
A complete list can be found on [http://octave.sourceforge.net/packages.php Octave-Forge].
+
== Octave-Forge ==
  
=== Packaging ===
+
Octave provides a set of packages, similar to Matlab's Toolboxes, through [http://octave.sourceforge.net/index.html Octave-Forge]. The complete list of packages is [http://octave.sourceforge.net/packages.php here].
  
Creating an Octave-forge package for Arch is easy using the [https://github.com/drizzd/octave-forge-archlinux#readme Octave-forge helper scripts for Archlinux].
+
Packages can be installed [[#Using Octave's installer]] or [[#Using the AUR]].
  
 
=== Using Octave's installer ===
 
=== Using Octave's installer ===
  
Packages can also be managed using Octave's installer. To install a package:
+
Packages can be managed using Octave's installer. They are installed to ~/octave, or in a system directory with the -global option. To install a package:
  
# Download the {{ic|.tar.gz}} package from Octave-Forge.
+
octave:1> pkg install -forge packagename
# Install it from Octave as user by executing:
 
  
octave:1> pkg install packagename.tar.gz
+
{{Note|Some Octave's packages, like {{ic|control}}, need the {{Pkg|gcc-fortran}} ArchLinux's package in order to compile and install.}}
 
 
Packages have dependencies which you have to install before installing your package, if you want to bypass this use:
 
 
 
octave:2> pkg install -no-deps packagename.tar.gz
 
  
 
To uninstall a package:
 
To uninstall a package:
 
   
 
   
  octave:3> pkg uninstall packagename.tar.gz
+
  octave:3> pkg uninstall packagename
  
 
Some packages get loaded automatically by Octave, for those which do not:
 
Some packages get loaded automatically by Octave, for those which do not:
Line 56: Line 50:
 
To see which packages have been loaded use {{ic|pkg list}}, the packages with an asterisk are the ones that are already loaded.
 
To see which packages have been loaded use {{ic|pkg list}}, the packages with an asterisk are the ones that are already loaded.
  
== Plotting ==
 
  
Octave has two official plotting backends:
+
A way to make sure that all packages gets loaded at Octave startup:
* {{App|[[Wikipedia:Gnuplot|Gnuplot]]|A classic Linux plotting utility.|http://www.gnuplot.info/|{{Pkg|gnuplot}}}}
 
* {{App|FLTK Backend|A new experimental OpenGL backend based on the [[Wikipedia:FLTK|FLTK]] GUI toolkit.|http://www.gnu.org/software/octave/|{{Pkg|octave}}}}
 
{{Note|To enable the FLTK backend, you need to install the {{Pkg|fltk}} package.}}
 
  
GnuPlot is still the default, but it can be changed by:
+
{{hc|/usr/share/octave/site/m/startup/octaverc|
 +
## System-wide startup file for Octave.
 +
##
 +
## This file should contain any commands that should be executed each
 +
## time Octave starts for every user at this site.
 +
pkg load all}}
  
octave:1> graphics_toolkit("fltk");
+
=== Using the AUR ===
  
To make this change permanent add it to your {{ic|~/.octaverc}} file.
+
Some packages may be found in the AUR ([https://aur.archlinux.org/packages.php?O=0&K=octave-&do_Search=Go search packages]). New Octave-forge packages for Arch can be created semi-automatically using the [https://github.com/drizzd/octave-forge-archlinux#readme Octave-forge helper scripts for Archlinux].
  
== Graphical interfaces ==
+
== Plotting ==
  
There are very few graphical interfaces for Octave and none of them are official:
+
Qt is the default plotting backend:
* {{App|Cantor|A graphical user interface that delegates its mathematical operations to one of several back ends (Scilab, Maxima, Octave and others).|http://edu.kde.org/cantor/|{{Pkg|kdeedu-cantor}}}}
 
* {{App|QtOctave|A Qt frontend for Octave.|https://forja.rediris.es/projects/csl-qtoctave/|{{AUR|qtoctave}}}}
 
  
== Reading Microsoft Excel Spreadsheets ==
+
>> available_graphics_toolkits
 +
ans =
 +
{
 +
  [1,1] = fltk
 +
  [1,2] = qt
 +
}
 +
>> graphics_toolkit
 +
ans = qt
  
There are several ways to read Microsoft Excel files with Octave.
+
Alternatively you can use either FLTK or Gnuplot backend (by installing {{Pkg|gnuplot}}) and running the following command:
  
==== Converting to an open format ====
+
>> graphics_toolkit("gnuplot");
  
The easiest way to use {{ic|.xls}} files in Octave would be to convert them to {{ic|.csv}} or {{ic|.ods}} using Calc (limited to 1024 columns) from [[Libreoffice]] or [http://www.calligra.org/sheets/ Sheets](limited to 32768 columns) from the the [http://www.calligra-suite.org/ Calligra Suite].
+
To make this change permanent add it to your {{ic|~/.octaverc}} file.
  
After the conversion is complete you can use the build-in Octave function {{ic|csvread}} for {{ic|.csv}} files:
+
== Reading Microsoft Excel Spreadsheets ==
 
 
octave:1> csvread('myfile.csv');
 
  
For {{ic|.ods}} files the {{AUR|octave-io}} package is necessary which contains the {{ic|odsread}} function:
+
You can open {{ic|.ods}}, {{ic|.xls}} and {{ic|.xlsx}} files with the {{ic|odsread}} or {{ic|xlsread}} function, which requires the {{AUR|octave-io}} package:
  
 
  octave:1> odsread('myfile.ods');
 
  octave:1> odsread('myfile.ods');
 +
octave:1> xlsread('myfile.xls');
 +
octave:1> xlsread('myfile.xlsx');
  
For {{ic|.xlsx}} files you can use the {{AUR|xlsx2csv}} package from [[AUR]]:
+
=== Converting to CSV format ===
  
  xlsx2csv -t /path/to/save/location -x /path/to/myfile.xlsx
+
Alternatively, first convert the files to {{ic|.csv}} using [[LibreOffice]] Calc ([https://bugs.documentfoundation.org/show_bug.cgi?id=50916 limited] to 1024 columns) or [http://www.calligra.org/sheets/ Calligra Sheets] ({{Pkg|calligra}}, limited to 32768 columns).
  
==== Reading xls files directly from Octave ====
+
After the conversion is complete you can use the build-in Octave function {{ic|csvread}} for {{ic|.csv}} files:
 
+
    
If you must work with XLS files and you cannot convert them to CSV or ODS, for whatever reason, you can use the {{ic|xlsread}} function from the {{AUR|octave-io}} package.
+
octave:1> csvread('myfile.csv');
 
 
{{ic|xlsread}} is Java-based and as such requires some [[Java]] libraries to enable support for XLS files.
 
 
 
The steps necessary to make it work are:
 
:1. [[Pacman|Install]] {{Pkg|jdk7-openjdk}}, available in the [[official repositories]].
 
 
 
{{Note|A common problem is that Octave cannot find the JDK path. To fix this execute the following commands in your shell:
 
$ export JAVA_HOME=/usr/lib/jvm/java-7-openjdk
 
You may also want to add this to your {{ic|~/.bashrc}} and append it to your {{ic|PATH}}.}}
 
 
 
:2. Install a Java XLS library for {{ic|xlsread}}. There are more such libraries available, a comparison can be found at [http://octave.org/wiki/index.php?title=IO_package#Comparison_of_interfaces_.26_usage here]. The recommended library is {{AUR|apache-poi}}, available in the [[AUR]].
 
 
 
:3. Finally, install the {{AUR|octave-java}} package from [[AUR]].
 
 
 
To check if Java is working correctly in Octave, see the output of:
 
 
 
   octave:1> javaclasspath
 
  STATIC JAVA PATH
 
      - empty -
 
  DYNAMIC JAVA PATH
 
      - empty -
 
 
 
To load the selected library in Octave, check if it is in the Java path. If not:
 
  octave:1> javaaddpath path/to/file.jar
 
In the case you chose {{AUR|apache-poi}}, the relevant JAR files can be found in {{ic|/usr/share/java/apache-poi/poi-3.x.jar}} and {{ic|/usr/share/java/apache-poi/poi-ooxml-3.x.jar}}.
 
 
 
To check if it works
 
  octave:1> chk_spreadsheet_support
 
  
The output should be > 0:
+
== Troubleshooting ==
                    0 No spreadsheet I/O support found
 
                  ---------- XLS (Excel) interfaces: ----------
 
                    1 = COM (ActiveX / Excel)
 
                    2 = POI (Java / Apache POI)
 
                    4 = POI+OOXML (Java / Apache POI)
 
                    8 = JXL (Java / JExcelAPI)
 
                  16 = OXS (Java / OpenXLS)
 
                  --- ODS (OpenOffice.org Calc) interfaces ----
 
                  32 = OTK (Java/ ODF Toolkit)
 
                  64 = JOD (Java / jOpenDocument)
 
                  ----------------- XLS & ODS: ----------------
 
                  128 = UNO (Java / UNO bridge - OpenOffice.org)
 
  
To make this permanent add the {{ic|javaaddpath}} commands to your {{ic|~/.octaverc}} file.
+
=== Zsh Undecodable Token ===
 +
If you get error
 +
undecodable token: b(hex)[23m
 +
when printing, install {{Pkg|grml-zsh-config}} and relogin.

Latest revision as of 19:31, 5 May 2017

From the official website:

GNU Octave is a high-level interpreted language, primarily intended for numerical computations. It provides capabilities for the numerical solution of linear and nonlinear problems, and for performing other numerical experiments. It also provides extensive graphics capabilities for data visualization and manipulation. Octave is normally used through its interactive command line interface, but it can also be used to write non-interactive programs. The Octave language is quite similar to Matlab so that most programs are easily portable.

Installation

Install the octave package.

Run the GUI app with octave or the CLI app with octave-cli.

Alternative graphical interfaces

The default octave GUI is included in the octave package. Alternatively, you can use one of the following unofficial GUIs:

  • Cantor — A graphical user interface that delegates its mathematical operations to one of several back ends (Scilab, Maxima, Octave and others).
http://edu.kde.org/cantor/ || cantor
  • QtOctave — A Qt frontend for Octave.
https://forja.rediris.es/projects/csl-qtoctave/ || qtoctaveAUR[broken link: package not found]

Octave-Forge

Octave provides a set of packages, similar to Matlab's Toolboxes, through Octave-Forge. The complete list of packages is here.

Packages can be installed #Using Octave's installer or #Using the AUR.

Using Octave's installer

Packages can be managed using Octave's installer. They are installed to ~/octave, or in a system directory with the -global option. To install a package:

octave:1> pkg install -forge packagename
Note: Some Octave's packages, like control, need the gcc-fortran ArchLinux's package in order to compile and install.

To uninstall a package:

octave:3> pkg uninstall packagename

Some packages get loaded automatically by Octave, for those which do not:

octave:4> pkg load packagename

or

octave:5> pkg load all

To see which packages have been loaded use pkg list, the packages with an asterisk are the ones that are already loaded.


A way to make sure that all packages gets loaded at Octave startup:

/usr/share/octave/site/m/startup/octaverc
## System-wide startup file for Octave.
##
## This file should contain any commands that should be executed each
## time Octave starts for every user at this site. 
 pkg load all

Using the AUR

Some packages may be found in the AUR (search packages). New Octave-forge packages for Arch can be created semi-automatically using the Octave-forge helper scripts for Archlinux.

Plotting

Qt is the default plotting backend:

>> available_graphics_toolkits
ans =
{
  [1,1] = fltk
  [1,2] = qt
}
>> graphics_toolkit
ans = qt

Alternatively you can use either FLTK or Gnuplot backend (by installing gnuplot) and running the following command:

>> graphics_toolkit("gnuplot");

To make this change permanent add it to your ~/.octaverc file.

Reading Microsoft Excel Spreadsheets

You can open .ods, .xls and .xlsx files with the odsread or xlsread function, which requires the octave-ioAUR package:

octave:1> odsread('myfile.ods');
octave:1> xlsread('myfile.xls');
octave:1> xlsread('myfile.xlsx');

Converting to CSV format

Alternatively, first convert the files to .csv using LibreOffice Calc (limited to 1024 columns) or Calligra Sheets (calligra, limited to 32768 columns).

After the conversion is complete you can use the build-in Octave function csvread for .csv files:

octave:1> csvread('myfile.csv');

Troubleshooting

Zsh Undecodable Token

If you get error

undecodable token: b(hex)[23m

when printing, install grml-zsh-config and relogin.