[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: MATLAB / Octave compatability, spacing, parsing
From: |
John W. Eaton |
Subject: |
Re: MATLAB / Octave compatability, spacing, parsing |
Date: |
Thu, 27 Oct 2005 15:49:13 -0400 |
On 27-Oct-2005, Steve C. Thompson wrote:
| MATLAB doesn't allow whitespace before the transpose
| operator.
|
| [0 1]'
|
| works in MATLAB, but
|
| [0 1] '
|
| doesn't. Octave properly parses both cases.
This is odd. The error is
>> [0 1] '
??? [0 1] '
|
Error: A MATLAB string constant is not terminated properly.
but
>> [0 1] 'x'
??? [0 1] 'x'
|
Error: Unexpected MATLAB expression.
so why should this use of a single quote character be misinterpreted
as the start of a character string?
Maybe this is related to the stupid kluge for command-style functions,
in which Matlab determines which way to parse something like
f + x
based on whitespace? For example, try the following function
function y = f (varargin)
varargin{:}
y = 1
and
f + 1
f+ 1
f +1
At least now they allow f() to force the function to be called without
any arguments.
| MATLAB always requires `...'.
|
| rand (1, ...
| 2)
|
| and
|
| rand (1,
| 2)
|
| both work in Octave. MATLAB chokes on the later.
Setting "warn_matlab_incompatible = true" in Octave will catch this one.
| Also, something else. MATLAB doesn't support `printf'.
|
| foo = 5;
| printf('My result is: %d\n', foo)
|
| works in Octave, but not MATLAB. If using MATLAB, the kludge
| is to issue `fprintf' instead:
|
| foo = 5;
| fprintf('My result is: %d\n', foo)
And of course Octave's fprintf is also equivalent to printf if the
first argument happens to be a character string. Octave has printf
because it somehow seems wrong to me to use an f* function when there
is no file ID argument.
jwe
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------