FAQ: Difference between revisions

Jump to navigation Jump to search
23,345 bytes removed ,  30 June 2022
m
adjusted list level for gdb
m (adjusted list level for gdb)
(30 intermediate revisions by 5 users not shown)
Line 8: Line 8:


* Search for an answer in our [https://lists.gnu.org/archive/html/help-octave/ mailing list archives]
* Search for an answer in our [https://lists.gnu.org/archive/html/help-octave/ mailing list archives]
* Contact our user community using our [https://lists.gnu.org/mailman/listinfo/help-octave help@octave.org mailing list] (feel free to subscribe to this mailing list for the latest updates and discussions)
* Contact our user community using our [https://octave.discourse.group Octave Discourse].
* Contact our user community using our [https://webchat.freenode.net/?channels=octave IRC chat room <code>#octave</code> in Freenode]
* Contact our user community using our [https://webchat.freenode.net/?channels=octave IRC chat room <code>#octave</code> in Freenode]


Line 28: Line 28:
==Who uses Octave?==
==Who uses Octave?==


A huge number of people ranging from students to researchers involved in various fields such as statistics,Machine Learning, data analytics, etc   . Universities use it for research and teaching, companies of all sizes for development and individuals for certain private purposes. See [[Who Uses Octave?]] for more clarity .
A huge number of people ranging from students to researchers involved in various fields such as statistics,Machine Learning, data analytics, etc. Universities use it for research and teaching, companies of all sizes for development and individuals for certain private purposes. See [[Who Uses Octave?]] for more clarity.


==Who develops Octave?==
==Who develops Octave?==
Line 42: Line 42:
The [https://www.gnu.org/ GNU Project] was launched in 1984 to develop a complete Unix-like operating system which is free software: the GNU system.  GNU is a recursive acronym for "GNU's Not Unix"; it is pronounced [https://www.gnu.org/gnu/pronunciation.en.html g'noo].
The [https://www.gnu.org/ GNU Project] was launched in 1984 to develop a complete Unix-like operating system which is free software: the GNU system.  GNU is a recursive acronym for "GNU's Not Unix"; it is pronounced [https://www.gnu.org/gnu/pronunciation.en.html g'noo].


The [https://www.fsf.org/ Free Software Foundation (FSF)] is the principal organisation that has sponsored the GNU Project.
The [https://www.fsf.org/ Free Software Foundation (FSF)] is the principal organization that has sponsored the GNU Project.


Octave became GNU Octave in 1997 (beginning with [[Release History|version 2.0.6]]).  This meant agreeing to consider Octave a part of the GNU Project and support the efforts of the FSF.  A big part of this effort is to adhere to the [https://www.gnu.org/prep/standards/standards.html GNU coding standards] and to benefit from GNU's infrastructure (e.g. [https://hg.savannah.gnu.org/hgweb/octave/ code hosting] and [http://bugs.octave.org bug tracking]).  Additionally, Octave receives [https://my.fsf.org/donate/working-together/octave sponsorship] from the FSF's Working Together fund.  However, Octave is not and has never been developed by the FSF.
Octave became GNU Octave in 1997 (beginning with [[Release History|version 2.0.6]]).  This meant agreeing to consider Octave a part of the GNU Project and support the efforts of the FSF.  A big part of this effort is to adhere to the [https://www.gnu.org/prep/standards/standards.html GNU coding standards] and to benefit from GNU's infrastructure (e.g. [https://hg.savannah.gnu.org/hgweb/octave/ code hosting] and [http://bugs.octave.org bug tracking]).  Additionally, Octave receives [https://my.fsf.org/donate/working-together/octave sponsorship] from the FSF's Working Together fund.  However, Octave is not and has never been developed by the FSF.
Line 52: Line 52:
   John W. Eaton, David Bateman, Søren Hauberg, Rik Wehbring ({{Release Year}}).
   John W. Eaton, David Bateman, Søren Hauberg, Rik Wehbring ({{Release Year}}).
   GNU Octave version {{Release}} manual: a high-level interactive language for numerical computations.
   GNU Octave version {{Release}} manual: a high-level interactive language for numerical computations.
   URL https://www.gnu.org/software/octave/doc/v{{Release}}/
   URL https://octave.org/doc/v{{Release}}/


A [https://en.wikipedia.org/wiki/BibTeX BibTeX] entry for [https://en.wikipedia.org/wiki/LaTeX LaTeX] users is:
A [https://en.wikipedia.org/wiki/BibTeX BibTeX] entry for [https://en.wikipedia.org/wiki/LaTeX LaTeX] users is:
Line 60: Line 60:
     author    = {John W. Eaton and David Bateman and S{\o}ren Hauberg and Rik Wehbring},
     author    = {John W. Eaton and David Bateman and S{\o}ren Hauberg and Rik Wehbring},
     year      = <span>{</span>{{Release Year}}},
     year      = <span>{</span>{{Release Year}}},
     url      = {https://www.gnu.org/software/octave/doc/v{{Release}}/},
     url      = {[https://octave.org/doc/v{{Release}}/ https://octave.org/doc/v{{Release}}/]},
   }
   }


Run {{manual|citation}} at the Octave prompt for details on how to best cite the Octave version you are running.  Certain Octave packages also have recommended citations in which case use <code>citation package_name</code>.
Run {{manual|citation}} at the Octave prompt for details on how to best cite the Octave version you are running.  Certain Octave packages also have recommended citations in which case use <code>citation package_name</code>.


Note that there are two reasons for citing the software used.  One is giving recognition to the work done by others which we have already addressed to . The other is giving details on the system used so that experiments can be replicated.  For this, you should cite the version of Octave and all packages used (you can get this information using the <code>ver</code> command), as well as any details of your setup as part of your Methods.  In addition, you should make your source available as well . See [http://software.ac.uk/so-exactly-what-software-did-you-use How to cite and describe software] for more details and an in depth discussion for the same .
Note that there are two reasons for citing the software used.  One is giving recognition to the work done by others which we have already addressed to. The other is giving details on the system used so that experiments can be replicated.  For this, you should cite the version of Octave and all packages used (you can get this information using the <code>ver</code> command), as well as any details of your setup as part of your Methods.  In addition, you should make your source available as well. See [http://software.ac.uk/so-exactly-what-software-did-you-use How to cite and describe software] for more details and an in depth discussion for the same.


==What documentation exists for Octave?==
==What documentation exists for Octave?==
Line 82: Line 82:
The following steps have been the solution to several bug reports and help requests.  Please try them before asking for further support.  If nothing below helps, please give us the following information:
The following steps have been the solution to several bug reports and help requests.  Please try them before asking for further support.  If nothing below helps, please give us the following information:


* Operating system: e.g. [https://support.microsoft.com/en-us/help/13443/windows-which-version-am-i-running '''Windows 10 (version 1909)'''] or '''Ubuntu 20.04'''
* Operating system: e.g. [https://support.microsoft.com/en-us/help/13443/windows-which-version-am-i-running '''MS Windows 10 (version 2004)'''] or '''Ubuntu 20.04'''
* GNU Octave version: e.g. '''Version {{Release}}'''
* GNU Octave version: e.g. '''Version {{Release}}'''
* Installation method: e.g. '''Downloaded and installed "octave-{{Release}}-w64-installer.exe" from https://www.octave.org/download.html'''
* Installation method: e.g. '''Downloaded and installed "octave-{{Release}}-w64-installer.exe" from https://www.octave.org/download.html'''
Line 88: Line 88:
=== MS Windows ===
=== MS Windows ===


* After upgrade the GUI does not open / shuts down immediately.
* After Octave upgrade the GUI does not open / shuts down immediately.
** '''Solution:''' Delete the folder {{path|C:\Users\YOUR_USER_NAME\.config\octave}}
** '''Solution:'''
*** Version 5.2.0 and older: Delete the folder {{path|C:\Users\YOUR_USER_NAME\.config\octave}}
*** Version 6.1.0 and newer: Delete the folder {{path|%APPDATA%\octave}}, which generally is located at {{path|C:\Users\YOUR_USER_NAME\AppData\Roaming\octave}}
* Missing/conflicting files.
* Missing/conflicting files.
** '''Solution:''' Remove/Uninstall all existing Octave versions.  Restart the system.  Install GNU Octave again.
** '''Solution:''' Remove/Uninstall all existing Octave versions.  Restart the system.  Install GNU Octave again.
* Permission errors.
 
** '''Solution 1:''' Consult your malware detection (a.k.a. AntiVirus) software, if files are blocked.
* Permission errors
** '''Solution 2:''' Did you install Octave on a network-drive?  Do you have the execution permissions?
** '''Solution 1:''' Octave versions prior to version 7.1.0 on MS Windows used VBS scripts to start the program.  You can test whether your system is blocking VBS scripts by doing the following:
**# Using Notepad or another text editor, create a text file containing only the text: <pre>msgbox("This is a test script, Click OK to close")</pre>
**# Save the file on your Desktop with the name {{Path|testscript.vbs}} (be sure that the editor didn't end it in .txt or .vbs.txt).
**# Double click the file.  If scripts can run, a popup window will appear with that message.
**#* If the file opens in notepad or an editor, it means it still ended in .txt.  MS Windows insecurely hides file extensions by default.  To show file extensions follow [https://answers.microsoft.com/en-us/windows/forum/all/in-win10-how-to-show-the-file-extension-for/ed21ff20-cdb3-4263-9c7d-fc6ed125fc82 these instructions at Microsoft.com].
**#* If both {{Path|testscript.vbs}} and {{Path|octave.vbs}} open a text- or other editor, it means your MS Windows file associations have .vbs files associated with another program.  To fix this, right click the .vbs file, select "Open With", select "Choose Another App", check the box that says "Always use this app to open .vbs files".  Finally, select "Microsoft Windows Based Script Host" from the list.  If it is not in the list, select "More apps".  If still not there, select "Look for Another App on this PC" and navigate to {{Path|C:\Windows\System32\wscript.exe}}, select it, and select "Open".  If {{Path|wscript}} is still not present you will need to seek assistance installing missing MS Windows components.
**# Try moving {{Path|testscript.vbs}} to another location, such as a {{Path|C:\temp folder}}.  Additionally try to move {{Path|testscript.vbs}} in the Octave installation folder containing {{Path|octave.vbs}} and see if VBS scripts can be run there.
**# If {{Path|testscript.vbs}} doesn't run in any of those locations, then scripting appears to be disabled or blocked on your system.  If {{Path|testscript.vbs}} runs in some locations but not others, there there may be other security permissions errors to be solved.  If {{Path|testscript.vbs}} runs in the same folder as {{Path|octave.vbs}}, but directly double-clicking on {{Path|octave.vbs}} does not start Octave, then there appears to be some problem other than script permissions.  
** '''Solution 2:''' Consult your malware detection (a.k.a. AntiVirus) software, if files are blocked.
** '''Solution 3:''' Did you install Octave on a network-drive?  Do you have the execution permissions?
** '''Solution 4:''' Is your computer managed by your company?  Does your administrator prohibit script execution?
===Collecting gdb backtrace information===
The following instructions can help you gather troubleshooting information that may help developers identify the problem if the above steps are ineffective:
* if Octave is 'hanging' (the process is remaining open):
*# attempt to start the Octave GUI
*# with the program stalled (either at the GUI, or with the black terminal window), open the Task Manager (right click on taskbar, select Task manager), switch to the "Details" tab, find `octave-gui.exe` on that list, ad take note of the corresponding PID (process ID)
*# Open the folder where Octave is installed. You should find a file called `cmdshell.bat` in the main folder. Run that file, which should open a MSYS2 bash (command line) window.
*# At that prompt, run `gdb -p <em>PID</em>` where <em>PID</em> is the process ID noted previously.
*# at the gdb prompt, execute `thread apply all bt`.  (If this returns a list longer than one page you may need to 'continue' by typing `c`.)
*# copy and paste that output into a text file and append it to your trouble report at octave.discourse.group or bug report at bugs.octave.org.
 
* if Octave is immediately crashing and closing:
*# Open the folder where Octave is installed. You should find a file called `cmdshell.bat` in the main folder. Run that file, which should open a MSYS2 bash (command line) window.
*# At that prompt, run `gdb octave`. (that will start gdb attached to the octave executable.)
*# At the gdb prompt, execute `r --gui`.  That should attempt to start the Octave in GUI mode.  The gdb prompt should stay unresponsive as long as octave is running.
*# If octave crashes, the gdb prompt should become responsive again. execute `thread apply all bt`.  (If this returns a list longer than one page you may need to 'continue' by typing `c`.)
*# copy and paste that output into a text file and append it to your trouble report at octave.discourse.group or bug report at bugs.octave.org.


==I do not see any output of my script until it has finished?==
==I do not see any output of my script until it has finished?==
Line 122: Line 150:
==Why is Octave's floating-point computation wrong?==
==Why is Octave's floating-point computation wrong?==


Floating-point arithmetic is an approximation '''in binary''' to arithmetic on real or complex numbers.  Just like you cannot represent 1/3 exactly in decimal arithmetic (0.333333... is only a rough approximation to 1/3), you cannot represent some fractions like <math>1/10</math> exactly in base 2.  In binary, the representation to one tenth is <math>0.0\overline{0011}_b</math> where the bar indicates that it repeats infinitely (like how <math>1/6 = 0.1\overline{6}_d</math> in decimal).  Because this infinite repetition cannot be represented exactly with a finite number of digits, rounding errors occur for values that appear to be exact in decimal but are in fact approximations in binary, such as for example how 0.3 - 0.2 - 0.1 is not equal to zero.
Floating-point arithmetic is an approximation '''in binary''' to arithmetic on real or complex numbers.  Just like you cannot represent 1/3 exactly in decimal arithmetic (0.333333... is only a rough approximation to 1/3 for any finite number of 3s), you cannot represent some fractions like <math>1/10</math> exactly in base 2.  In binary, the representation to one tenth is <math>0.0\overline{0011}_b</math> where the bar indicates that it repeats infinitely (like how <math>1/6 = 0.1\overline{6}_d</math> in decimal).  Because this infinite repetition cannot be represented exactly with a finite number of digits, rounding errors occur for values that appear to be exact in decimal but are in fact approximations in binary, such as for example how 0.3 - 0.2 - 0.1 is not equal to zero.


In addition, some advanced operations are computed by approximation and there is no guarantee for them to be accurate, see [https://en.wikipedia.org/wiki/Rounding#Table-maker.27s_dilemma Table-maker's dilemma] for further references . Their results are system-dependent.
In addition, some advanced operations are computed by approximation and there is no guarantee for them to be accurate, see [https://en.wikipedia.org/wiki/Rounding#Table-maker.27s_dilemma Table-maker's dilemma] for further references. Their results are system-dependent.


This isn't a bug that is limited to GNU-Octave & it happens with any program that uses [https://en.wikipedia.org/wiki/IEEE_754 IEEE 754 floating-point arithmetic].  To be fair, IEEE 754 also specifies decimal floating-point arithmetic, which has never seen wide adoption.  The reason why Octave and other programs using IEEE 754 binary floating-point numbers is that they are ''fast'', because they are implemented in hardware or system libraries.  Unless you are using very exotic hardware, Octave will use your computer's processor for basic floating-point arithmetic.
This isn't a bug that is limited to GNU-Octave & it happens with any program that uses [https://en.wikipedia.org/wiki/IEEE_754 IEEE 754 floating-point arithmetic].  To be fair, IEEE 754 also specifies decimal floating-point arithmetic, which has never seen wide adoption.  The reason why Octave and other programs using IEEE 754 binary floating-point numbers is that they are ''fast'', because they are implemented in hardware or system libraries.  Unless you are using very exotic hardware, Octave will use your computer's processor for basic floating-point arithmetic.
Line 136: Line 164:
Some windows users with integrated Intel GPUs have reported missing lines when printing with an OpenGL toolkit like FLTK or Qt. {{bug|42534}}
Some windows users with integrated Intel GPUs have reported missing lines when printing with an OpenGL toolkit like FLTK or Qt. {{bug|42534}}


Users with this kind of problem should try to install/update their Intel OpenGL drivers for Windows or consider installing Mesa drivers from http://qt-project.org/wiki/Cross-compiling-Mesa-for-Windows .
Users with this kind of problem should try to install/update their Intel OpenGL drivers for Windows or consider installing Mesa drivers from http://qt-project.org/wiki/Cross-compiling-Mesa-for-Windows.


See also https://www.opengl.org/wiki/FAQ#Why_is_my_GL_version_only_1.4_or_lower.3F .
See also https://www.opengl.org/wiki/FAQ#Why_is_my_GL_version_only_1.4_or_lower.3F .
Line 146: Line 174:
==Error message about invalid call to script or invalid use of script in index expression==
==Error message about invalid call to script or invalid use of script in index expression==


If Octave shows an error message about {{Codeline|invalid call to script .../close.m}} or {{Codeline|invalid use of of script .../close.m in index expression}}, it means that you have created a script called close.m that is overriding the built-in Octave function {{Codeline|close}}. Octave functions and scripts share the same global namespace. It is best to avoid creating your own scripts or functions that have the same name as an Octave function as to avoid this error regarding the invalid call to script or invalid use of script in index expression .
If Octave shows an error message about {{Codeline|invalid call to script .../close.m}} or {{Codeline|invalid use of of script .../close.m in index expression}}, it means that you have created a script called close.m that is overriding the built-in Octave function {{Codeline|close}}. Octave functions and scripts share the same global namespace. It is best to avoid creating your own scripts or functions that have the same name as an Octave function as to avoid this error regarding the invalid call to script or invalid use of script in index expression.


=Licensing issues=
=Licensing issues=
Line 185: Line 213:
==How can I install Octave on Windows?==
==How can I install Octave on Windows?==


:'' So as to install GNU-Octave for windows O.S. See: [[Octave for Microsoft Windows]]''
:'' So as to install GNU-Octave for Windows O.S, refer to : [[Octave for Microsoft Windows]]''


==How can I install Octave on macOS?==
==How can I install Octave on MacOS?==


:''See: [[Octave for macOS]]''
:''So as to install GNU-Octave for MacOS, refer to : [[Octave for macOS]]''


==How can I install Octave on GNU/Linux?==
==How can I install Octave on GNU/Linux?==


:''See: [[Octave for GNU/Linux]]''
:'' So as to install GNU-Octave on GNU/Linux, refer to: [[Octave for GNU/Linux]]''


==How can I install Octave on Android / what is this Octave app in the Google Play store?==
==How to install Octave on Android OR What is the Octave app available in the Google Play store?==


There is an '''unofficial''' Octave app available for Android in the Google Play store.  Please see [[Octave for Android]] for more information.
There is an '''unofficial''' Octave app available for Android in the Google Play store.  Please see [[Octave for Android]] for further  information.


==How can I install Octave on platform X?==
==How can I install Octave on platform X?==
Line 230: Line 258:
==What do I need to build Octave from the source code?==
==What do I need to build Octave from the source code?==


For a list of build dependencies see [[Building]].
For a list of build dependencies, refer to  [[Building]].


==Do I need GCC to build Octave from the source code?==
==Do I need GCC to build Octave from the source code?==


No. The development is done primarily with [https://gcc.gnu.org/ GCC], so you may hit some incompatibilities.  Octave is intended to be portable to any standard conforming compiler (for example [https://clang.llvm.org/ clang] is know to work as well).  If you have difficulties that you think are bugs, please report them to the [http://bugs.octave.org bug tracker], or ask for help on the [https://lists.gnu.org/mailman/listinfo/help-octave help@octave.org mailing list].
No. The development is done primarily with [https://gcc.gnu.org/ GCC], so you may hit some incompatibilities.  Octave is intended to be portable to any standard conforming compiler (for example [https://clang.llvm.org/ clang] is known to work as well).  If you face any difficulties that you think are bugs, please report them to the [http://bugs.octave.org bug tracker], or ask for help on the [https://lists.gnu.org/mailman/listinfo/help-octave help@octave.org mailing list].


=What's new in Octave?=
=What's new in Octave?=


Each new Octave release introduces many new features.  A complete list of user visible changes can be seen by running <code>news</code> at the Octave prompt.  The following changes are a distilled list of the major changes:
Each new Octave release introduces many new features.  A complete list of user visible changes can be seen by running <code>news</code> at the Octave prompt.
 
==What's new in the next version of Octave?==
 
See the [http://hg.savannah.gnu.org/hgweb/octave/file/tip/NEWS NEWS file] on the development branch.
 
==What's new in version series 4.0.X of Octave==
 
See the complete user-visible changes on the [https://www.gnu.org/software/octave/NEWS-4.0.html NEWS file].
 
* First official release of the GUI.
* Release of official windows binaries.
* Experimental support for [[classdef]].
* OpenGL graphics with Qt widgets.
* Several functions for reading, writing, and recording of audio.
 
==What's new in version series 3.8.X of Octave==
 
See the complete user-visible changes on the [https://www.gnu.org/software/octave/NEWS-3.8.html NEWS file].
 
* Experimental GUI interface.
* OpenGL graphics with fltk widgets.
* Support for nested functions.
* Support for java packages in Octave core.
* Reading and writing of image files vastly extended.


==What's new in version series 3.6.X of Octave==
* '''What's new in the next version of Octave?'''
 
** See the [https://hg.savannah.gnu.org/hgweb/octave/file/tip/NEWS NEWS file] on the development branch.
See the complete user-visible changes on the [https://www.gnu.org/software/octave/NEWS-3.6.html NEWS file].
* '''What was new in Octave Version X.Y.Z?'''
 
** See [[Release History]].
* Perl compatible regular expressions
* A profiler has been added.
* Broadcasting enabled for all built-in binary element-wise operators.
* Performance of all m-file string functions has been improved.
 
==What's new in version series 3.4.X of Octave==
 
See the complete user-visible changes on the [https://www.gnu.org/software/octave/NEWS-3.4.html NEWS file].
 
* Many improvements to native OpenGL plotting
* ARPACK now distributed with Octave
* Indexing optimizations
* FTP objects
* Function handles aware of overloaded functions
* bsxfun optimized for basic arithmetic functions
* Matlab-style ignoring of output arguments using {{Codeline|~}}
* Many optimizations of the accumarray function
* Sparse matrix indexing has been rewritten for speed
* The pkg command now accepts a -forge option to pull packages directly from Octave Forge
 
==What's new in version series 3.2.X of Octave==
 
See the complete user-visible changes on the [https://www.gnu.org/software/octave/NEWS-3.2.html NEWS file].
 
* Single precision type
* Experimental OpenGL graphics toolkit to replace gnuplot
* Object orient programming via @class named directories
* 64-bit compilation support
* gzipped files and stream and consequently support of Matlab v7 files
* a fully compatible MEX interface
* imwrite and imread (based on the GraphicsMagick library)
* Lazy transpose: Special treatment in the parser of things like "a' * b", where the transpose is never explicitly formed but a flag is rather passed to the underlying LAPACK code.
 
==Older releases==
 
For full details on older releases, see:
 
* [http://hg.savannah.gnu.org/hgweb/octave/file/83792dd9bcc1/etc/NEWS.1 NEWS.1] for the 1.X.Y series
* [http://hg.savannah.gnu.org/hgweb/octave/file/83792dd9bcc1/etc/NEWS.2 NEWS.2] for the 2.X.Y series
* [http://hg.savannah.gnu.org/hgweb/octave/file/83792dd9bcc1/etc/NEWS.3 NEWS.3] for the 3.X.Y series


=Packages and Octave Forge=
=Packages and Octave Forge=
Line 455: Line 419:
==How do I increase Octave's precision?==
==How do I increase Octave's precision?==


Octave's default numerical type is [https://en.wikipedia.org/wiki/IEEE_754 IEEE 754] binary64 , a.k.a. "double" or "hardware floats".  This type has a precision of 53 bits or about 16 decimal digits. It is supported by each modern computer hardware, so it is really '''fast'''.  This type is assumed throughout for Octave's calculations.  If more precision was required, one can obtain a "few bits more" by using integer types, e.g. {{manual|uint64}}, but in general one cannot expect more precision from any '''fast''' numerical software.  Just to visualize "how big" those numerical limits are, consider the following table:
Octave's default numerical type is [https://en.wikipedia.org/wiki/IEEE_754 IEEE 754] binary64, a.k.a. "double" or "hardware floats".  This type has a precision of 53 bits or about 16 decimal digits. It is supported by each modern computer hardware, so it is really '''fast'''.  This type is assumed throughout for Octave's calculations.  If more precision was required, one can obtain a "few bits more" by using integer types, e.g. {{manual|uint64}}, but in general one cannot expect more precision from any '''fast''' numerical software.  Just to visualize "how big" those numerical limits are, consider the following table:


{| class="wikitable"
{| class="wikitable"
Line 515: Line 479:
   >> corr
   >> corr
   corr    corrcoef
   corr    corrcoef


=Differences between Octave and Matlab=
=Differences between Octave and Matlab=
 
:''See [[Differences between Octave and Matlab]]''.
People often ask
 
<blockquote>
I wrote some code for Matlab, and I want to get it running under Octave.  Is there anything I should watch out for?
</blockquote>
 
or alternatively
 
<blockquote>
I wrote some code in Octave, and want to share it with Matlab users.  Is there anything I should watch out for?
</blockquote>
 
which is not quite the same thing.  There are still a number of differences between Octave and Matlab, however in general differences between the two are considered as bugs.  Octave might consider that the bug is in Matlab and do nothing about it, but generally functionality is almost identical.  If you find an important functional difference between Octave behavior and Matlab, then you should send a description of this difference (with code illustrating the difference, if possible) to http://bugs.octave.org.
 
Furthermore, Octave adds a few syntactical extensions to Matlab that might cause some issues when exchanging files between Matlab and Octave users.
 
As both Octave and Matlab are under constant development, the information in this section is subject to change.
 
You should also look at the pages http://octave.sourceforge.net/packages.php and http://octave.sourceforge.net/docs.html that have a function reference that is up to date. You can use this function reference to see the number of octave functions that are available and their Matlab compatibility.
 
==Graphical Curve Fitting Tool==
 
Currently, Octave lacks a graphical curve fitting tool such as Matlab's [https://www.mathworks.com/help/curvefit/curvefitting-app.html curvefit] tool. [https://lists.gnu.org/archive/html/help-octave/2015-07/msg00300.html]
 
You can use polyfit or the packages [https://octave.sourceforge.io/signal/ signal] or [https://octave.sourceforge.io/optim/ optim] to achieve these task but these are not graphical tools.
 
==Nested Functions==
 
Octave has limited support for nested functions since version 3.8.0. That is
 
<syntaxhighlight lang="Matlab">
function y = foo (x)
  y = bar(x)
  function y = bar (x)
    y = ...;
  end
end
</syntaxhighlight>
 
is equivalent to
 
<syntaxhighlight lang="Octave">
function y = foo (x)
  y = bar(x)
endfunction
 
function y = bar (x)
  y = ...;
endfunction
</syntaxhighlight>
 
The main difference with Matlab is a matter of scope.  While nested functions have access to the parent function's scope in Matlab, no such thing is available in Octave, due to how Octave essentially “un-nests” nested functions.
 
The authors of Octave consider the nested function scoping rules of Matlab to be more problems than they are worth as they introduce difficult to find bugs as inadvertently modifying a variable in a nested function that is also used in the parent is particularly easy for those not attentive to detail.
 
==Differences in core syntax==
 
There are a few core Matlab syntaxes that are not accepted by Octave, these being
 
* Some limitations on the use of function handles.  The major difference is related to nested function scoping rules (as above) and their use with function handles.
 
* Some limitations of variable argument lists on the LHS of an expression, though the most common types are accepted.
 
* Matlab classdef object oriented programming is only partially supported, see [[classdef]] for details.
 
==Differences in core functions==
 
A large number of the Matlab core functions (i.e. those that are in the core and not a toolbox) are implemented, and certainly all of the commonly used ones.  There are a few functions that aren't implemented, usually to do with specific missing Octave functionality (GUI, DLL, Java, ActiveX, DDE, web, and serial functions).  Some of the core functions have limitations that aren't in the Matlab version.  For example the {{manual|sprandn}} function can not force a particular condition number for the matrix like Matlab can.  Another example is that testing and the runtests function work differently in Matlab and Octave.
 
==Just-In-Time compiler==
 
Matlab includes a "Just-In-Time" compiler.  This compiler allows the acceleration of for-loops in Matlab to almost native performance with certain restrictions.  The JIT must know the return type of all functions called in the loops and so you can't include user functions in the loop of JIT optimized loops.  Octave has a [[JIT|not fully functional JIT compiler]].  For this reason you must [[Performance#Vectorization|vectorize your code]] as much as possible.  The MathWorks themselves have a good document discussing vectorization at http://www.mathworks.com/support/tech-notes/1100/1109.html.
 
==Compiler==
 
On a related point, there is no Octave compiler, and so you can't convert your Octave code into a binary for additional speed or distribution.
 
==Graphic handles==
 
The support for graphics handles is converging towards full compatibility.  If you notice any incompatibilities, please [http://bugs.octave.org report a bug].
 
==GUI functions==
 
The support for [http://www.octave.org/doc/interpreter/GUI-Development.html Matlab compatible GUI functions] was added in Octave version 3.6.0 and is converging towards full compatibility.  If you notice any incompatibilities, please [http://bugs.octave.org report a bug].
 
==Simulink==
 
Octave itself includes no Simulink support.  Typically the simulink models lag research and are less flexible, so shouldn't really be used in a research environment.  However, some Matlab users that try to use Octave complain about this lack.
 
==MEX-Files==
 
Octave includes an [http://www.octave.org/doc/interpreter/Mex_002dFiles.html API to the Matlab MEX interface].  However, as MEX is an API to the internals of Matlab and the internals of Octave differ from Matlab, there is necessarily a manipulation of the data to convert from a MEX interface to the Octave equivalent.  This is notable for all complex matrices, where Matlab stores complex arrays as real and imaginary parts, whereas Octave respects the C99/C++ standards of co-locating the real/imag parts in memory.  Also due to the way Matlab allows access to the arrays passed through a pointer, the MEX interface might require copies of arrays (even non complex ones).
 
==Block comments==
 
Block comments denoted by <code>#{</code> and <code>#}</code> markers (or  <code>%{</code> and <code>%}</code>) are supported by Octave with some limitations.  The major limitation is that block comments are not supported within [] or {}.
 
==Mat-File format==
 
There are some differences in the mat v5 file format accepted by Octave.  Matlab recently introduced the "-V7.3" save option which is an HDF5 format which is particularly useful for 64-bit platforms where the standard Matlab format can not correctly save variables.  Octave accepts HDF5 files, but is not yet compatible with the "-v7.3" versions produced by Matlab.
 
Although Octave can load inline function handles saved by Matlab, it can not yet save them.
 
Finally, some multi-byte Unicode characters aren't yet treated in mat-files.
 
==Profiler==
 
Thanks to Daniel Kraft's 2011 Google Summer of Code project, [http://www.octave.org/doc/interpreter/Profiling.html Octave has a profiler] since version 3.6.0.
 
==Toolboxes==
 
Octave is a community project and so the toolboxes that exist are donated by those interested in them through [[Octave Forge]].  These might be lacking in certain functionality relative to the Matlab toolboxes, and might not exactly duplicate the Matlab functionality or interface.
 
==Short-circuit <code>&</code> and <code>|</code> operators==
 
The <code>&</code> and <code>|</code> operators in Matlab short-circuit when included in a condition (e.g. an {{Codeline|if}} or {{Codeline|while}} statement) and not otherwise.  In Octave only the <code>&&</code> and <code>||</code> short circuit.  Note that this means that
 
<syntaxhighlight lang="Octave">
if (a | b)
  ...
end
</syntaxhighlight>
 
and
 
<syntaxhighlight lang="Octave">
t = a | b;
if (t)
  ...
end
</syntaxhighlight>
 
have different semantics in Matlab.  This is really a Matlab bug, but there is too much code out there that relies on this behavior to change it.  Prefer the <code>&&</code> and <code>||</code> operators in {{Codeline|if}} statements if possible.
 
Note that the difference with Matlab is also significant when either argument is a function with side effects or if the first argument is a scalar and the second argument is an empty matrix.  For example, note the difference between
 
<syntaxhighlight lang="Octave">
t = 1 | [];          ## results in [], so...
if (t) 1, end        ## in if ([]), this is false.
</syntaxhighlight>
 
and
 
<syntaxhighlight lang="Octave">
if (1 | []) 1, end  ## short circuits so condition is true.
</syntaxhighlight>
 
In the latter case, Octave displays since version 4.0.0 a warning:
 
  warning: Matlab-style short-circuit operation performed for operator |
 
Another case that is documented in the Matlab manuals is that
 
<syntaxhighlight lang="Matlab">
t = [1, 1] | [1, 2, 3];          ## error
if ([1, 1] | [1, 2, 3]) 1, end  ## OK
</syntaxhighlight>
 
Also Matlab requires the operands of <code>&&</code> and <code>||</code> to be scalar values but Octave does not (it just applies the rule that for an operand to be considered true, every element of the object must be nonzero or logically true).
 
Finally, note the inconsistence of thinking of the condition of an {{Codeline|if}} statement as being equivalent to {{Codeline|all(X(:))}} when {{Codeline|X}} is a matrix. This is true for all cases EXCEPT empty matrices:
 
<syntaxhighlight lang="Matlab">
if ([0, 1]) == if (all ([0, 1]))  ==>  i.e., condition is false.
if ([1, 1]) == if (all ([1, 1]))  ==>  i.e., condition is true.
</syntaxhighlight>
 
However,
 
<syntaxhighlight lang="Matlab">
if ([])
</syntaxhighlight>
 
is not the same as
 
<syntaxhighlight lang="Matlab">
if (all ([]))
</syntaxhighlight>
 
because, despite the name, the {{manual|all}} is really returning true if none of the elements of the matrix are zero, and since there are no elements, well, none of them are zero.  This is an example of [https://en.wikipedia.org/wiki/Vacuous_truth vacuous truth].  But, somewhere along the line, someone decided that {{Codeline|if ([])}} should be false.  The Mathworks probably thought it just looks wrong to have {{Codeline|[]}} be true in this context even if you can use logical gymnastics to convince yourself that "all" the elements of an empty matrix are nonzero.  Octave however duplicates this behavior for {{Codeline|if}} statements containing empty matrices.
 
==Solvers for singular, under- and over-determined matrices==
 
Matlab's solvers as used by the operators {{manual|mldivide}} <code>\</code> and {{manual|mrdivide}} <code>/</code>, use a different approach than Octave's in the case of singular, under-, or over-determined matrices.  In the case of a singular matrix, Matlab returns the result given by the LU decomposition, even though the underlying solver has flagged the result as erroneous.  Octave has made the choice of falling back to a minimum norm solution of matrices that have been flagged as singular which arguably is a better result for these cases.
 
In the case of under- or over-determined matrices, Octave continues to use a minimum norm solution, whereas Matlab uses an approach that is equivalent to
 
<syntaxhighlight lang="Octave">
function x = mldivide (A, b)
  m = rows (A);
  [Q, R, E] = qr (A);
  x = [A \ b, E(:, 1:m) * (R(:, 1:m) \ (Q' * b))]
end
</syntaxhighlight>
 
While this approach is certainly faster and uses less memory than Octave's minimum norm approach, this approach seems to be inferior in other ways.
 
A numerical question arises: how big can the null space component become, relative to the minimum-norm solution?  Can it be nicely bounded, or can it be arbitrarily big?  Consider this example:
 
<syntaxhighlight lang="Octave">
m = 10;
n = 10000;
A = ones (m, n) + 1e-6 * randn (m, n);
b = ones (m, 1) + 1e-6 * randn (m, 1);
norm (A \ b)
</syntaxhighlight>
 
while Octave's minimum-norm values are about 3e-2, Matlab's results are 50-times larger.  For another issue, try this code:
 
<syntaxhighlight lang="Octave">
m = 5;
n = 100;
j = floor (m * rand (1, n)) + 1;
b = ones (m, 1);
A = zeros (m, n);
A(sub2ind(size(A),j,1:n)) = 1;
x = A \ b;
[~,p] = sort (rand (1, n));
y = A(:,p) \ b;
norm (x(p) - y)
</syntaxhighlight>
 
It shows that unlike in Octave, {{manual|mldivide}} in Matlab is not invariant with respect to column permutations. If there are multiple columns of the same norm, permuting columns of the matrix gets you different result than permuting the solution vector. This will surprise many users.
 
Since the {{manual|mldivide}} <code>\</code> and {{manual|mrdivide}} <code>/</code> operators are often part of a more complex expression, where there is no room to react to warnings or flags, it should prefer intelligence (robustness) to speed, and so the Octave developers are firmly of the opinion that Octave's approach for singular, under- and over-determined matrices is a better choice than Matlab's.
 
==Octave extensions==
 
The extensions in Octave over MATLAB syntax are very useful, but might cause issues when sharing with Matlab users. A list of the major extensions that should be avoided to be compatible with Matlab are:
 
Comments in Octave can be marked with {{Codeline|#}}. This allows POSIX systems to have the first line as {{Codeline|#! octave -q}} and mark the script itself executable. MATLAB doesn't have this feature due to the absence of comments starting with {{Codeline|#}}".
 
Code blocks like if, for, while, etc can be terminated with block specific terminations like endif. MATLAB doesn't have this and all blocks must be terminated with end.
 
Octave has a lisp-like {{Codeline|unwind_protect}} block that allows blocks of code that terminate in an error to ensure that the variables that are touched are restored. You can do something similar with try/catch combined with {{Codeline|rethrow (lasterror ())}} in Matlab, however rethrow and lasterror are only available in Octave 2.9.10 and later. MATLAB 2008a also introduced {{Codeline|OnCleanUp}} that is similar to {{Codeline|unwind_protect}}, except that the object created by this function has to be explicitly cleared in order for the cleanup code to run.
 
Note that using try/catch combined with {{Codeline|rethrow (lasterror ())}} cannot guarantee that global variables will be correctly reset, as it won't catch user interrupts with Ctrl-C. For example
 
<syntaxhighlight lang="Matlab">
global a
a = 1;
try
  _a = a;
  a = 2
  while true
  end
catch
  fprintf ('caught interrupt\n');
  a = _a;
  rethrow (lasterror());
end
</syntaxhighlight>
 
compared to
 
<syntaxhighlight lang="Octave">
global a
a = 1;
unwind_protect
  _a = a;
  a = 2
  while true
  end
unwind_protect_cleanup
  fprintf ('caught interrupt\n');
  a = _a;
end
</syntaxhighlight>
 
Typing Ctrl-C in the first case returns the user directly to the prompt, and the variable <code>a</code> is not reset to the saved value. In the second case the variable <code>a</code> is reset correctly.  Therefore Matlab gives no safe way of temporarily changing global variables.
 
Indexing can be applied to all objects in Octave and not just variables. Therefore {{Codeline|sin(x)(1:10)}} for example is perfectly valid in Octave but not Matlab. To do the same in Matlab you must do {{Codeline|y &#61; sin(x); y &#61; y([1:10]);}}
 
Octave has the operators {{Codeline|++}}, {{Codeline|–-}}, {{Codeline|-&#61;}}, {{Codeline|+&#61;}}, {{Codeline|*&#61;}}, etc. As MATLAB doesn't, if you are sharing code these should be avoided.
 
Character strings in Octave can be denoted with double or single quotes. There is a subtle difference between the two in that escaped characters like {{Codeline|\n}} (newline), {{Codeline|\t}} (tab), etc are interpreted in double quoted strings but not single quoted strings. This difference is important on Windows platforms where the {{Codeline|\}} character is used in path names, and so single quoted strings should be used in paths. MATLAB doesn't have double quoted strings and so they should be avoided if the code will be transferred to a MATLAB user.
 
==What features are unique to Octave?==
 
Although most of the Octave language will be familiar to Matlab users, it has some unique features of its own.
 
=== Functions defined on the command-line===
Functions can be defined by entering code on the command line, a feature not supported by Matlab. For example, you may type:
 
<syntaxhighlight lang="Octave">
>> function s = hello_string (to_who)
> ## Say hello
> if nargin<1, to_who = "World"; end
> s = ["Hello ",\
>      to_who];
> endfunction
>> hello_string ("Moon")
ans = Hello Moon
</syntaxhighlight>
 
As a natural extension of this, functions can also be defined in script files (m-files whose first non-comment line isn't {{Codeline|function out &#61; foo (...)}})
 
Note: MATLAB R2016b added the ability to [http://www.mathworks.com/help/matlab/matlab_prog/local-functions-in-scripts.html define functions in script files].
 
===Comments with #===
 
The pound character, {{Codeline|#}}, may be used to start comments, in addition to {{Codeline|%}}. See the previous example. The major advantage of this is that as {{Codeline|#}} is also a comment character for unix script files, any file that starts with a string like {{Codeline|#! /usr/bin/octave -q}} will be treated as an octave script and be executed by octave.
 
===Strings delimited by double quotes "===
 
In 2016, Matlab introduced String Arrays, that are initialized by using double quoted strings, and are not implemented in Octave yet.  In Octave double-quoted strings include backslash interpretation (like C++, C, and Perl) while single quoted are uninterpreted (like Matlab and Perl).
 
===Line continuation by backslash===
 
Lines can be continued with a backslash, {{Codeline|\}}, in addition to three points {{Codeline|...}} as in Matlab.
 
===Informative block closing===
 
You may close function, for, while, if, ... blocks with endfunction, endfor, endwhile, ... keywords in addition to using end. As with Matlab, the end (or endfunction) keyword that marks the end of a function defined in a .m file is optional.
 
===Coherent syntax===
 
Indexing other things than variables is possible, as in:
 
<syntaxhighlight lang="Octave">
>> [3 1 4 1 5 9](3)
ans = 4
>> cos([0 pi pi/4 7])(3)
ans = 0.70711
</syntaxhighlight>
 
In Matlab, it is for example necessary to assign the intermediate result {{Codeline|cos([0 pi pi/4 7])}} to a variable before it can be indexed again.
 
===Exclamation mark as not operator===
 
The exclamation mark {{Codeline|!}} (aka “Bang!”) is a negation operator, just like the tilde {{Codeline|~}}:
 
<syntaxhighlight lang="Octave">
>> if ! strcmp (program_name, "octave"),
>  "It's an error"
> else
>  "It works!"
> end
ans = It works!
</syntaxhighlight>
 
Note however that Matlab uses the {{Codeline|!}} operator for shell escapes, for which Octave requires using the system command.
 
===Increment and decrement operators===
 
If you like the {{Codeline|++}}, {{Codeline|+&#61;}} etc operators, rejoice! Octave includes the C-like increment and decrement operators {{Codeline|++}} and {{Codeline|--}} in both their prefix and postfix forms, in addition to {{Codeline|+&#61;}}, {{Codeline|-&#61;}}, {{Codeline|*&#61;}}, {{Codeline|/&#61;}}, {{Codeline|^&#61;}},{{Codeline|.+&#61;}},{{Codeline|.-&#61;}},{{Codeline|.*&#61;}}, {{Codeline|./&#61;}} and {{Codeline|.^&#61;}}.
 
For example, to pre-increment the variable x, you would write {{Codeline|++x}}. This would add one to x and then return the new value of x as the result of the expression. It is exactly the same as the expression {{Codeline|x &#61; x + 1}}.
 
To post-increment a variable x, you would write {{Codeline|x++}}. This adds one to the variable x, but returns the value that x had prior to incrementing it. For example, if x is equal to 2, the result of the expression x++ is 2, and the new value of x is 3.
 
For matrix and vector arguments, the increment and decrement operators work on each element of the operand.
 
===Unwind-protect===
 
In addition to try-catch blocks, Octave supports an alternative form of exception handling modeled after the unwind-protect form of Lisp. The general form of an unwind_protect block looks like this:
 
<syntaxhighlight lang="Octave">
unwind_protect
  body
unwind_protect_cleanup
  cleanup
end_unwind_protect
</syntaxhighlight>
 
Where body and cleanup are both optional and may contain any Octave expressions or commands. The statements in cleanup are guaranteed to be executed regardless of how control exits body.
 
The unwind_protect statement is often used to reliably restore the values of global variables that need to be temporarily changed.
 
Matlab can be made to do something similar with their {{manaul|onCleanup}} function that was introduced in 2008a. Octave also has {{manual|onCleanup}} since version 3.4.0.
 
===Built-in ODE and DAE solvers===
 
Octave includes LSODE, DASSL and DASPK for solving systems of stiff ordinary differential and differential-algebraic equations. These functions are built in to the interpreter.
 
===Do-Until loop structure===
 
Similar to the do-while loop in C and C++, Octave allows a do-until loop which does not exist in Matlab:
 
<syntaxhighlight lang="Octave">
x = 0
do
  x += 1;
until (x == 10)
</syntaxhighlight>
 
===Broadcasting===
 
Borrowed from [http://stackoverflow.com/q/26948776/3565696 other languages], [http://www.octave.org/doc/interpreter/Broadcasting.html octave broadcasting] allows easy and readable vectorization.
 
<syntaxhighlight lang="Octave">
f = (1:0.1:2);
# put angular frequencies on the first dimension to prepare broadcasting
omega = 2 * pi * f(:);
# time is already on the second dimension (row vector)
t = 0:0.02:2;
# the resulting s will be a 2-dimensional array
s = sin(omega .* t);
# which can be displayed as
pcolor(t, f, s)
xlabel("t (s)")
ylabel("f (Hz)")
</syntaxhighlight>
 
Note: [https://www.mathworks.com/help/matlab/matlab_prog/compatible-array-sizes-for-basic-operations.html Automatic expansion of dimensions] was added to MATLAB R2016b.
 
===Documentation strings===
 
Octave allows extensive formatting of the help string of functions using Texinfo. The effect on the online documentation is relatively small, but makes the help string of functions conform to the help of Octave’s own functions. However, the effect on the appearance of printed or online documentation will be greatly improved.
 
===Test functions===
 
Octave allows to add self-tests to user defined functions. Tests are put after function definition in specially commented block.
 
<syntaxhighlight lang="Octave">
function mult = a(val)
  mult = val.*2;
endfunction
%!test
%! assert (a(3), 6);
</syntaxhighlight>
 
Such a function can be tested for valid outputs by following code:
 
  >> test a
  PASSES 1 out of 1 test
 
===Demonstration Functions===
 
Example code block can be part of function file in a similar manner as test functions.  For example to run {{manual|demo}} for function multinom of package specfun, use:
 
  demo multinom
 
===Powerful assert===
 
Function assert have extended input possibilities.


=[https://en.wikipedia.org/wiki/Graphical_user_interface GUI]=
=[https://en.wikipedia.org/wiki/Graphical_user_interface GUI]=
Line 1,008: Line 535:
This is one of those times where the best documentation is to read the existing code.  We have three different toolkits in Octave now, so there are some examples to draw from.
This is one of those times where the best documentation is to read the existing code.  We have three different toolkits in Octave now, so there are some examples to draw from.


=Development=
= Development =
 
==When will feature X be released or implemented?==
 
When it's ready, sooner [http://www.octave.org/get-involved.html if you help].  You can [https://savannah.gnu.org/patch/?group=octave send us patches] if you can implement feature X yourself.  If you can't, some [http://www.octave.org/commercial-support.html developers may be convinced to work on your specific problem for some money].
 
==How can I get involved in Octave development?==


Be around.  Be social.  Participate in our mailing lists [https://lists.gnu.org/mailman/listinfo/help-octave help@octave.org] and [https://lists.gnu.org/mailman/listinfo/octave-maintainers maintainers@octave.org].  Find things about Octave you don't like, and start thinking about how to fix them.  Many people who now contribute to Octave first spent several years helping in the mailing list before they started to delve into the code.  A good way to learn Octave is to understand the problems other people are having with it, so being helpful in the mailing lists not only helps Octave as a whole, but it also prepares you to be a better Octave contributor.
== When will feature X be released or implemented? ==


If you feel ready to dive right into the code, read the [[Developers]] wiki page or [http://www.octave.org/get-involved.html start here].  But do not send an email to the mailing lists listing your skills and offering to helpWe won't just suggest things for you to do. We lack volunteers and we do need your help, but because of that, we also lack the time to provide good guidance and mentoring. If there is a specific short-term project you would like to work on, say so, and just do it.  Then ask for help or advice when you're doing it.  It is a lot more important that you do something that you're actually interested on than something we suggested because it only matches your skills.
When it's ready, sooner [https://www.octave.org/get-involved.html if you help].  You can [https://savannah.gnu.org/patch/?group=octave send us patches] if you can implement feature X yourselfIf you can't, some [https://www.octave.org/commercial-support.html developers may be convinced to work on your specific problem for some money].


We also need help with this wiki and the [http://www.octave.org/doc/interpreter/ manual].  These are also important tasks.  The documentation is easy to patch, and the help text for individual functions even more so.  Editing this wiki is even easier.
== How can I get involved in Octave development? ==


Accurate bug reporting is also very useful.  Find and report [http://bugs.octave.org/ bugs], making an attempt to diagnose them.  Eventually, you will also know how to fix them.  If you want to help with bug reports or patches, subscribe to the [https://lists.gnu.org/mailman/listinfo/octave-bug-tracker bug tracker mailing list].  You'll get updates on all bug activity, and you can jump in when you see
:''See [[Developer FAQ]]''.
something you can help with.


Look at our [[projects]], [[short projects]], and [[Summer of Code - Getting Started]] if you need specific inspiration for coding tasks that we would like to get done.
[[Category:FAQ]]
153

edits

Navigation menu