octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

differences matlab vs octave


From: David Bateman
Subject: differences matlab vs octave
Date: Wed, 09 May 2007 11:51:32 +0200
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

Dear All,

I was asked to summarize the differences between matlab and octave
internally, and so thought I might share that analysis here as it might
be of use to others, and might be used to fix the wiki that has errors
in what is compatible and what isn't.

Regards
David

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. Furthermore, Octave
adds a few syntactical  extensions to Matlab that might cause some
issues when exchanging files between Matlab and Octave users. Finally,
Octave is under constant development, and so changes can happen rapidly
so this analysis might change at anytime.

The major difference between Octave 2.9.10 and Matlab are

* Octave doesn't yet have nested functions. That if

function y = foo (x)
   y = bar(x)
   function y = bar (x)
      y = ...;
   end
end

There was discussion in Octave of having these even prior to Matlab, and
Octave had private sub-functions in the same m-file before Matlab, the
decision was made not to have these in Octave at the time for
compatibility. The above written with sub-functions functions would be

function y = foo (x)
   y = bar(x)
end
function y = bar (x)
   y = ...;
end

Now that Matlab has recently introduced nested functions I expect Octave
while have them soon as well. Till then nested functions in Octave are
treated as sub-functions with the same scoping rules as sub-functions.
In fact if you've ever written nested functions with matlab, you'll know
that these scoping rules are more of a hassle than anything else as its
really easy to inadvertently modify a variable in a sub-function.

* There a few core Matlab syntaxes that are not accepted by Octave,
these being

 - Some limitations on the use of function handles, some of these were
addressed in 2.9.10. The major difference is related to nested function
scoping rules (as above) and there use with function handles.

 - Some limitations of variable argument lists on the LHS of an
expression, though the most common types are accepted. I'm not sure
whether this was improved for 2.9.9 or just afterwards

 - Matlab object-oriented classes with overloading etc through the
subasgn and "@" directories is not treated by Octave. There is work to
remove this restriction in the future, and in fact is in a sub-branch of
the Octave CVS, so expect this restriction to be removed shortly.

 - Matlab private directories are not treated, though as for classes,
this will change in the near future. This restriction alleviated by
using addpath on the private directories, but this makes the private
directories visible in the global scope

* The vast majority 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,
for example condest. Some of the core functions have limitations that
aren't in the Matlab version. For example in 2.9.10 the interpN function
can only do linear interpolation and not cubic spline, etc.. However the
interp and interp2 function can....

* 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. Matlab themselves produces a good document discussing
vectorization at http://www.mathworks.com/support/tech-notes/1100/1109.html

* 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 is an example of how to do this at
http://www.stud.tu-ilmenau.de/~rueckn/, but this is a very early example
code and would need lots of work to complete it.

* Up to octave 2.9.9 there was no support for graphic handles in Octave
itself. There is in Octave 2.9.10, and so user extensions such as
OctPlot support graphic handles, and so the graphics between Octave and
Matlab are currently in the process of converging to a common interface.
Note that there basic graphic handle stuff is in place in 2.9.10, but
not things like "patch", "barseries", etc

* There is no Matlab compatible GUI functions. There are a number of
bindings from Octave to tcl/tk , vtk and zenity for example that can be
used for a GUI, but these are not matlab compatible. This might be an
issue if you intend to exchange octave code with matlab users. For
simulation code you rarely use GUI functions and so this might not be an
issue.

* 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. There is a similar package to simulink
for the Octave and R projects available at http://www.scicraft.org/

* 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 to
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 that copies of arrays (even non complex ones). Finally, in
2.9.9 there are some memory leaks in the MEX code that are fixed in the
2.9.10 release.

* Matlab recently included the possibility to have block comments. With
the "%{" and "%}" markers. Octave doesn't yet have block comments, but
might in the future.

* 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. Octave accepts hdf5 files, but is not yet compatible with
the "-v7.3" versions produced by Matlab. Octave 2.9.10 can't load/save
the inline or function handles saved in dot-mat files by matlab (though
can in its own format). There is some work to fix this, but the matlab
function handle format in mat-files is undocumented and this is
therefore not easy to address. Some multi-byte unicode characters aren't
yet treated in mat-files.

* Octave doesn't have a profiler. Though there is a patch for a flat
profiler, that might become a real profiler sometime in the future. see
the thread

http://www.cae.wisc.edu/pipermail/octave-maintainers/2007-January/001685.html

for more details

* Octave is a community project and so the toolboxes that exist are
donated by those interested in them through the octave-forge website
(octave.sf.net). These might be lacking in certain functionality
relative to the Matlab toolboxes

* The extensions in Octave over Matlab syntax are very useful, but might
cause issues when sharing with Matlab users. This is of particular
importance in the context of transfers of code for use with users of
Matlab. A list of the major extensions that should be avoided to be
compatible with Matlab are
  - Comments in octave can be marked with "#". This allows POSIX systems
to have the first line as "#! octave -q" and mark the script itself
executable. Matlab doesn't have this feature due the the absence of
comments starting with "#"

  - 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 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 rethrow(lasterror()) in Matlab, however rethrow and
lasterror were only just introduced in Octave and so aren't in 2.9.9,
but are in 2.9.10

  - Indexing can be applied to all objects in Octave and not just
variable. Therefore "sin(x)[1:10];" for example is perfectly legal in
Octave but not Matlab. To do the same in Matlab you must do "y = sin(x);
y = y([1:10]);"

  - Octave has the operators "++", "--", "-=", "+=", "*=", etc. As
Matlab doesn't, if you are sharing code these should be avoided

  - Strings in Octave can be denoted with double or single quotes. There
is a subtle difference between the two in that escaped characters like
\n, etc are interpreted in double quoted strings but not single quoted
strings. This difference is important on Windows platforms where the "\"
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 transfered to a matlab user

With graphic handles and the Octave package manager being introduced,
octave is really in the process of migrating lots of functionality right
now, and so if you choose to use Octave you really need to follow the
evolutions closely at the moment.. You might also like to look at the
page http://octave.sourceforge.net/packages.html and
http://octave.sourceforge.net/doc/ that has a function reference that is
up to date with octave 2.9.10. You can use this function reference to
see the number of octave function that are available and their Matlab
compatibility.

If you want a windows binary, the best one at the moment is also on my
personal machine at

http://www.dbateman.org/?page=octave&lang=EN

and in particular at

http://www.dbateman.org/octave/octave_20070126(2.9.9+)_setup.exe

This version is based on a CVS copy of Octave dated 26 Jan 2007, it 
doesn't include the graphic handles that will be in 2.9.10 but include
SSE2 optimized ATLAS binaries for acceleration. As it is a CVS version
of octave, you must also consider that it isn't supported. Furthermore,
as it is built with microsoft MSVC if you want to build mex files or
oct-files you'll need to install microsoft msvc express. I expected a
real windows binary to be released similar to the above version.


-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



reply via email to

[Prev in Thread] Current Thread [Next in Thread]