Академический Документы
Профессиональный Документы
Культура Документы
Some of the differences that do exist between Octave and MATLAB can be worked around using "user preference
variables."
GNU Octave is mostly compatible with Matlab. However, Octave's parser allows some (often very useful) syntax
that Matlab's does not, so programs written for Octave might not run in Matlab. For example, Octave supports the
use of both single and double quotes. Matlab only supports single quotes, which means parsing errors will occur if
you try to use double quotes (e.g. in an Octave script when run on Matlab). Octave and Matlab users who must
collaborate with each other need to take note of these issues and program accordingly.
Note: Octave can be run in "traditional mode" (by including the --traditional flag when starting
Octave) which makes it give an error when certain Octave only syntax is used.
This chapter documents instances where Matlab's parser will fail to run code that will run in Octave, and instances
where Octave's parser will fail to run code that will run in Matlab. This page also contains notes on differences
between things that are different between Octave (in traditional mode) and Matlab.
Temporaries
Octave and Matlab support temporary expressions.
tmp = size(mtx);
columns = tmp(2);
columns = size(mtx)(2);
columns = size(mtx,2);
%
%
%
works in both
works in Octave, fails in Matlab
works in both
Product of booleans
Matlab (R2011b) and Octave (3.6.4) responds differently when computing the product of boolean values:
X = ones(2,2) ; prod(size(X)==1)
Matlab: PROD is only supported for floating point input.
Octave: ans = 0
nargin
Matlab (R2011b) will not allow the following; Octave will.
function myfun = testfun(c)
if (nargin == 1)
nargin = 2;
else
nargin=3
end
startup.m
Matlab will execute a file named 'startup.m' in the directory it was called from on the command line. Octave does
not. It will, however, execute a file named '.octaverc' which can be edited to execute existing files. This means that
'.octaverc' can be edited to look for and execute a 'startup.m' file.
if ( exist ('startup.m', 'file') )
source ('startup.m') # load startup.m like matlab
endif
['abc ';'abc']
['abc ';'abc'] is allowed in Octave; Matlab returns: ?? Error using ==> vertcat
In Octave the result will be a 2 by 4 matrix where the last element of the last row is a space.
Calling Shells
the "! STRING" syntax calls a shell with command STRING in Matlab. Octave does not recognize ! as system call,
since it is used in logical operations. Always use 'system (STRING)' for compatibility.
If you really miss the one-character shortcut, for convenience on the command line you can create a similar shortcut
by defining the following in your '.octaverc' file:
function S(a), system(a); end
Now "S STRING" will evaluate the string in the shell.
Whitespace
Matlab does not allow whitespace before the transpose operator but Octave does (it is just an operator like others).
[0 1]'
[0 1] '
Line continuation
Matlab always requires `...' for line continuation.
rand (1, ...
2)
while Octave also supports
rand (1,
2)
and
rand (1, \
2)
References
[1] http:/ / wiki. octave. org/ FAQ#GUI
http://wiki.octave.org/FAQ#How_is_Octave_different_from_Matlab.3F
License
Creative Commons Attribution-Share Alike 3.0
//creativecommons.org/licenses/by-sa/3.0/