MATLAB Programming Differences Between Octave and MATLAB
MATLAB Programming Differences Between Octave and MATLAB
3 Product of booleans
MATLAB (R2011b) and Octave (3.6.4) responds dierSome of the dierences that do exist between Octave and
ently when computing the product of boolean values:
MATLAB can be worked around using user preference
X = ones(2,2) ; prod(size(X)==1) MATLAB: PROD is
variables.
only supported for oating point input. Octave: ans = 0
GNU Octave is mostly compatible with MATLAB. However, Octaves parser allows some (often very useful) syntax that MATLABs does not, so programs written for
Octave might not run in MATLAB. For example, Octave 4 nargin
supports the use of both single and double quotes. MATLAB only supports single quotes, which means parsing Nargin returns the number of input arguments of a funcerrors will occur if you try to use double quotes (e.g. in an tion. MATLAB (R2011b) will not allow the following;
Octave script when run on MATLAB). Octave and MAT- Octave will.
LAB users who must collaborate with each other need to
function myfun = testfun(c) if (nargin == 1) nargin = 2;
take note of these issues and program accordingly.
else nargin = 3 end
Note: Octave can be run in traditional mode
(by including the --traditional ag when starting Octave) which makes it give an error when
certain Octave-only syntax is used.
5 startup.m
MATLAB will execute a le named 'startup.m' in the directory it was called from on the command line. Octave
does not. It will, however, execute a le named '.octaverc'
which can be edited to execute existing les. This means
that '.octaverc' can be edited to look for and execute a
'startup.m' le.
Calling Shells
Octave supports both printf and fprintf as a command for Small dierences exist - an example is c2d. Here are the
printing to the screen. MATLAB requires fprintf:
two formats for the bilinear transformation with an analog
foo = 5; printf ('My result is: %d\n', foo) % Prints to model C:
STDOUT. Octave only
discrete = c2d(C,0.5,'tustin'); % Matlab
fprintf covers writing both to the screen and to a le by
omitting the optional le-handle argument:
Whitespace
MATLAB does not allow whitespace before the transpose operator but Octave does (it is just an operator like
others).
[0 1]' % works in MATLAB and Octave [0 1] ' % works
only in Octave
11
Line continuation
MATLAB uses the percent sign '%' to begin a comment. Octave uses both the hash symbol # and the
percent sign % interchangeably.
For exponentiation, Octave can use ^ or **; MATLAB requires ^.
For string delimiters, Octave can use ' or "; MATLAB requires '.
To end blocks, Octave can use end or specify the
block with endif, endfor, ...; MATLAB requires
end.
Octave supports C-style hexadecimal notation (e.g.
0xF0); MATLAB requires the hex2dec function
(e.g. hex2dec('F0')").
If something (like Netlab) need a function called fcnchk, you can just put the following into a le called
fcnchk.m and put it somewhere Octave can nd it:
3
function f=fcnchk(x, n) f = x; end
The main dierence is the lack of GUI for Octave.
There have been many attempts to solve this issue
though they are all eventually abandoned once they
no longer work with new Octave versions. There is
an experimental GUI as part of Octave already released, which is planned to become ocial with the
next release.
15
16
References
http://wiki.octave.org/FAQ#How_is_Octave_
different_from_Matlab.3F
17
See also
18
18
18.1
18.2
Images
18.3
Content license