octave-maintainers
[Top][All Lists]
Advanced

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

differences matlab vs octave


From: John W. Eaton
Subject: differences matlab vs octave
Date: Wed, 9 May 2007 14:40:16 -0400

On  9-May-2007, David Bateman wrote:

Overall I think this is a great start.  It will be a big improvement
to have this text replace the obsolete information that has been
around for so long now.

Should we include this information with the Octave sources?

| Octave had private sub-functions in the same m-file before Matlab, the

That's not correct, but it is true that when I added subfunctions, I
considered generalizing them to nested functions and this was before
nested functions were available in Matlab.  It's probably good that I
decided not to implement nested functions because I don't think I
would have chosen the same scoping rules.

| * 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.

I haven't compared lately, but I'm not sure it is the vast majority,
though with more than 1500 functions, I think there is enough
functionality to get at least some real work done.  I'd guess that the
fraction of Matlab core functions is more like 50% if you look at
everything.  If you omit the profiling, debugging, graphics, gui, dll,
java, activex, dde, web, and serial functions then the fraction is
somewhat higher.

| * 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

And are in some cases not even attempts at providing compatible
interfaces or functionality.

|   - 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

I don't think try/catch can really do what unwind_protect does.  For
example, try this in Octave and Matlab:

  try
    while true
    end
  catch
    fprintf ('caught interrupt\n');
  end

and type Control-C while it is executing the while loop.  You should
just end up back at the prompt without seeing the "caught interrupt"
message.  Then try the following in Octave:

  unwind_protect
    while true
    end
  unwind_protect_cleanup
    fprintf ('caught interrupt\n');
  end

and type Control-C while it is executing the loop.  You should see the
"caught interrupt" message here.

The difference is that the code in the cleanup block is executed no
matter how the interpreter exits the first block of the unwind_protect
statement, but the catch block of a try/catch statement is executed
only if an error occurs in the try part (and an interrupt is not an
error, but may still require some cleanup action).  So with Matlab,
how are you supposed to safely change global values?

|   - 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]);"

I think you mean sin(x)(1:10).

Also, there should be no need to place a range inside square brackets
(if something fails to work unless you do that, then it is a bug).
Note the difference between

  typeinfo (1:1000)
  typeinfo ([1:1000])

and

  sizeof (1:1000)
  sizeof ([1:1000])

Though many operations on ranges will result in converting the range
to a matrix, I think it is best to allow Octave to decide when that is
needed.

(Also please consider using "valid" instead of "legal" since we aren't
discussing laws that might be broken and land you in jail).

Thanks,

jwe


reply via email to

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