FAQ: Difference between revisions

Jump to navigation Jump to search
1,376 bytes added ,  2 May 2017
→‎Why GNU Octave?: Corrected pronunciation of "GNU"
(→‎Why GNU Octave?: Corrected pronunciation of "GNU")
(15 intermediate revisions by 9 users not shown)
Line 1: Line 1:
This is a list of frequently asked questions (FAQ) for GNU Octave users.
This is a list of frequently asked questions (FAQ) for GNU Octave users.


We are always looking for new questions (with answers), better answers, or both. Feel free to edit this page with your changes. If you have general questions about GNU Octave, or need help for something that is not covered by the Octave manual or the FAQ, please use the [https://mailman.cae.wisc.edu/listinfo/help-octave help@octave.org mailing list].
We are always looking for new questions (with answers), better answers, or both. Feel free to edit this page with your changes. If you have general questions about GNU Octave, or need help for something that is not covered by the Octave manual or the FAQ, please use the [https://lists.gnu.org/mailman/listinfo/help-octave help@octave.org mailing list].


This FAQ is intended to supplement, not replace, the GNU Octave manual. Before posting a question to the [https://mailman.cae.wisc.edu/listinfo/help-octave help@octave.org mailing list], you should first check to see if the topic is covered in the manual.
This FAQ is intended to supplement, not replace, the GNU Octave manual ([https://www.gnu.org/software/octave/doc/interpreter/ HTML], [https://www.gnu.org/software/octave/octave.pdf PDF]). Before posting a question to the [https://lists.gnu.org/mailman/listinfo/help-octave help@octave.org mailing list], you should first check to see if the topic is covered in the manual.
 
<div class="tocinline">__TOC__</div>


=General=
=General=
Line 18: Line 20:


==What is Octave-Forge?==
==What is Octave-Forge?==
[http://octave.sourceforge.net/ Octave-Forge] is a collection of packages for GNU Octave, something similar to the Matlab toolboxes. When talking about the two projects at the same time, GNU Octave is usually referred to as Octave core (or just ''core''). [http://octave.sourceforge.net/ Octave-Forge] also serves as a test bed for code that may eventually end up in the core, and distributes binaries for systems with a lack of developers tools (mainly Windows).
 
[https://octave.sourceforge.io/ Octave-Forge] is a collection of packages for GNU Octave, something similar to the Matlab toolboxes. When talking about the two projects at the same time, GNU Octave is usually referred to as Octave core (or just ''core''). [https://octave.sourceforge.io/ Octave-Forge] also serves as a test bed for code that may eventually end up in the core, and distributes binaries for systems with a lack of developers tools (mainly Windows).


==Who uses Octave?==
==Who uses Octave?==
Line 36: Line 39:
The GNU Project was launched in 1984 to develop a complete Unix-like operating system which is free software: the GNU system.
The 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 guh-noo, approximately like canoe.
GNU is a recursive acronym for “GNU's Not Unix”; it is pronounced g'noo, [https://www.gnu.org/gnu/pronunciation.en.html like “grew” but with the letter “n” instead of “r”].


The Free Software Foundation (FSF) is the principal organizational sponsor of the GNU Project.
The Free Software Foundation (FSF) is the principal organizational sponsor of the GNU Project.
Line 59: Line 62:


Octave is also free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 3, as published by the Free Software Foundation, or at your option any later version.
Octave is also free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 3, as published by the Free Software Foundation, or at your option any later version.
==Why are the developers planning to replace Gnuplot with an OpenGL backend?==
The development of Octave is committed to being both compatible with Matlab and adding additional features. Toward those ends, the development community has chosen to introduce a native OpenGL backend that supports Matlab handle graphics and its uicontrols. Starting with the 3.8 release, Octave now uses OpenGL graphics by default with FLTK widgets. A Qt OpenGL toolkit is also [https://github.com/goffioul/QtHandles under development].
There are no plans to remove the gnuplot backend. While a better backend may some day become the new default plotter, the gnuplot backend will still be available as long as our users find it useful.


== How can I cite Octave? ==
== How can I cite Octave? ==
Line 312: Line 309:


* http://www.octave.org/download.html
* http://www.octave.org/download.html
* ftp://ftp.octave.org/pub/octave/
* https://ftp.gnu.org/gnu/octave/


Since Octave is distributed under the terms of the GPL, you can get Octave from a friend who has a copy, or from the Octave website.
Since Octave is distributed under the terms of the GPL, you can get Octave from a friend who has a copy, or from the Octave website.
Line 326: Line 323:
* http://www.octave.org/download.html
* http://www.octave.org/download.html


As of today, Octave binaries are available at least on Debian, Ubuntu, RedHat, Suse, and Fedora GNU/Linux; Mac OS X; and Windows (versions 98, 2000, XP, Vista, 7 and 8).
As of today, Octave binaries are available at least on Debian, Ubuntu, RedHat, Suse, and Fedora GNU/Linux; Mac OS X; and Windows (versions 98, 2000, XP, Vista, 7, 8, and 10).


==How do I get a copy of Octave for (some other platform)?==
==How do I get a copy of Octave for (some other platform)?==
Line 409: Line 406:


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 (...)}})
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 #===
===Comments with #===
Line 490: Line 489:
===Broadcasting===
===Broadcasting===


Borrowed from [http://stackoverflow.com/q/26948776/3565696 other languages], [http://www.gnu.org/software/octave/doc/v4.0.1/Broadcasting.html octave broadcasting] allows easy and readable vectorialization.
Borrowed from [http://stackoverflow.com/q/26948776/3565696 other languages], [http://www.gnu.org/software/octave/doc/v4.0.1/Broadcasting.html octave broadcasting] allows easy and readable vectorization.


   f = (1:0.1:2);
   f = (1:0.1:2);
Line 503: Line 502:
   xlabel("t (s)")
   xlabel("t (s)")
   ylabel("f (Hz)")
   ylabel("f (Hz)")
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.


==How does Octave solve linear systems?==
==How does Octave solve linear systems?==
Line 649: Line 650:
==How do I run a Matlab P-file in Octave?==
==How do I run a Matlab P-file in Octave?==


You can't. Matlab P-files, also known as P-code, are [https://en.wikipedia.org/wiki/Obfuscation_%28software%29 obfuscated] files than cannot be run outside Matlab itself.
You can't. Matlab P-files (files with a .p file extension), also known as P-code, are [https://en.wikipedia.org/wiki/Obfuscation_%28software%29 obfuscated] files than cannot be run outside of Matlab itself. The original source Matlab m-files that were used to generate the P-files should be used in Octave instead.


Matlab P-files will ''never'' be supported in Octave, since there is no publicly-available algorithm to decode them.
There are no plans to support running P-files produced by Matlab in Octave.


=Common problems=
=Common problems=
Line 716: Line 717:
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


=Porting programs from Matlab to Octave=
== Plot hangs and makes the GUI unresponsive ==
 
If the Qt graphics toolkit is used and "plot" is used for the first time, the fontconfig scanner searches the font directory to build a font cache. This can take up to 3min on slow CPUs. See {{bug|45458}}
 
= Differences between Octave and Matlab =


People often ask
People often ask
Line 738: Line 743:
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.
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.


==How is Octave different from Matlab?==
== Nested Functions ==
 
The major differences between Octave 3.4.N and Matlab R2010b are:
 
===Nested Functions===
Octave has limited support for nested functions. That is
Octave has limited support for nested functions. That is


Line 765: Line 766:
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.
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===
== Differences in core syntax ==


There are a few core Matlab syntaxes that are not accepted by Octave, these being
There are a few core Matlab syntaxes that are not accepted by Octave, these being
Line 775: Line 776:
* Matlab classdef object oriented programming is not yet supported, though work is underway in a branch of the development tree.
* Matlab classdef object oriented programming is not yet supported, though work is underway in a branch of the development tree.


===Differences in core functions===
== Differences in core functions ==


A large number of the Matlab core functions (ie 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 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.
A large number of the Matlab core functions (ie 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 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===
== 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 doesn't have a JIT and so to some might seem slower than Matlab. For this reason you must 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.
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 doesn't have a JIT and so to some might seem slower than Matlab. For this reason you must 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===
== 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. There have been several aborted attempts at creating an Octave compiler. Should the JIT compiler above ever be implemented, an Octave compiler should be more feasible.
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. There have been several aborted attempts at creating an Octave compiler. Should the JIT compiler above ever be implemented, an Octave compiler should be more feasible.


===Graphic handles===
== Graphic handles ==


Up to Octave 2.9.9 there was no support for graphic handles in Octave itself. In the 3.2.N versions of Octave and beyond, the support for graphics handles is converging towards full compatibility. The patch function is currently limited to 2-D patches, due to an underlying limitation in gnuplot, but the experimental OpenGL backend is starting to see an implementation of 3-D patches.
Up to Octave 2.9.9 there was no support for graphic handles in Octave itself. In the 3.2.N versions of Octave and beyond, the support for graphics handles is converging towards full compatibility. The patch function is currently limited to 2-D patches, due to an underlying limitation in gnuplot, but the experimental OpenGL backend is starting to see an implementation of 3-D patches.


===GUI functions ===
== GUI functions ==


There are no Matlab compatible GUI functions yet.  This might be an issue if you intend to exchange Octave code with Matlab users. There are a number of bindings from Octave to {{Forge|tcl-octave|Tcl/Tk}}, [http://octaviz.sourceforge.net/index.php? VTK] and {{Forge|zenity}} for example, that can be used for a GUI, but these are not Matlab compatible. Work on a Matlab compatible GUI is in an alpha stage in the QtHandles project, which may form part of a future release of Octave.
There are no Matlab compatible GUI functions yet.  This might be an issue if you intend to exchange Octave code with Matlab users. There are a number of bindings from Octave to {{Forge|tcl-octave|Tcl/Tk}}, [http://octaviz.sourceforge.net/index.php? VTK] and {{Forge|zenity}} for example, that can be used for a GUI, but these are not Matlab compatible. Work on a Matlab compatible GUI is in an alpha stage in the QtHandles project, which may form part of a future release of Octave.


===Simulink===
== 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.
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===
== MEX-Files ==


Octave includes an 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).
Octave includes an 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 ==


Block comments denoted by {{Codeline|#{}} and {{Codeline|#&#125;}}  markers (or {{Codeline|%{}} and {{Codeline|%&#125;}}) are supported by Octave with some limitations. The major limitation is that block comments are not supported within [] or {}.
Block comments denoted by {{Codeline|#{}} and {{Codeline|#&#125;}}  markers (or {{Codeline|%{}} and {{Codeline|%&#125;}}) are supported by Octave with some limitations. The major limitation is that block comments are not supported within [] or {}.


===Mat-File format===
== 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.
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.
Line 815: Line 816:
Finally, some multi-byte Unicode characters aren't yet treated in mat-files.
Finally, some multi-byte Unicode characters aren't yet treated in mat-files.


===Profiler===
== Profiler ==


Thanks to Daniel Kraft's 2011 Google Summer of Code project, Octave has a profiler since version 3.6.0. However, at the moment it only produces text output and has its own makeshift interface for hierarchical profiling.
Thanks to Daniel Kraft's 2011 Google Summer of Code project, Octave has a profiler since version 3.6.0. However, at the moment it only produces text output and has its own makeshift interface for hierarchical profiling.


===Toolboxes===
== 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.
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 {{Codeline|&}} and {{Codeline|&#124;}} operators===
== Short-circuit {{Codeline|&}} and {{Codeline|&#124;}} operators ==


The {{Codeline|&}} and {{Codeline|&#124;}} 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 {{Codeline|&&}} and {{Codeline|&#124;&#124;}} short circuit. Note that this means that
The {{Codeline|&}} and {{Codeline|&#124;}} 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 {{Codeline|&&}} and {{Codeline|&#124;&#124;}} short circuit. Note that this means that
Line 873: Line 874:
because, despite the name, the {{Codeline|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 [http://en.wikipedia.org/wiki/Vacuous_truth vacuous truth]. But, somewhere along the line, someone decided that {{Codeline|if ([])}} should be false. 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.
because, despite the name, the {{Codeline|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 [http://en.wikipedia.org/wiki/Vacuous_truth vacuous truth]. But, somewhere along the line, someone decided that {{Codeline|if ([])}} should be false. 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===
== Solvers for singular, under- and over-determined matrices ==


Matlab's solvers as used by the operators mldivide (\) and mrdivide (/), 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.
Matlab's solvers as used by the operators mldivide (\) and mrdivide (/), 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.
Line 912: Line 913:
Since the mldivide (\) and mrdivide (/) 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.
Since the mldivide (\) and mrdivide (/) 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===
== 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:
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:
Line 986: Line 987:
made it free software so we could reuse large chunks of it which were
made it free software so we could reuse large chunks of it which were
incorporated in what is now the Octave GUI.
incorporated in what is now the Octave GUI.
=Graphics: backends and toolkits=
==What are the supported graphics backends?==
The current default is OpenGL, through the "qt" graphics toolkit.  The "ftlk" toolkit also relies on OpenGL.
Alternatively, Gnuplot can be used as a graphics backend by selecting the "gnuplot" graphics toolkit.
==Why did you replace Gnuplot with an OpenGL backend?==
The development of Octave is committed to being both compatible with Matlab and adding additional features. Toward those ends, the development community has chosen to introduce a native OpenGL backend that supports Matlab handle graphics and its uicontrols. Starting with the 3.8 release, Octave uses OpenGL graphics by default (with FLTK widgets in Octave 3.8 and Qt widgets in Octave 4.0 and later).
==Are there any plans to remove the gnuplot backend?==
There are no plans to remove the gnuplot backend. Even though the default graphics toolkit is now "qt", which uses OpenGL graphics with Qt widgets, the gnuplot backend will still be available as long as our users find it useful.
==How can I implement a new graphics backend/toolkit?==
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.
Anonymous user

Navigation menu