[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{
From: |
John W. Eaton |
Subject: |
Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{:}) |
Date: |
Mon, 8 Aug 2011 14:04:14 -0400 |
On 8-Aug-2011, Sergei Steshenko wrote:
| comma separated list is _not_ converted when 'sizeof' is called, but
| some _deafault_ conversion is called in case of
|
| "
| octave:4> foo_cs = foo{:}
| foo_cs = a
The expression
foo = {a, b, c}
foo{:}
behaves as if you had typed
foo = {a, b, c}
a, b, c
In other words, a "comma-separated list" is a set of
independent expressions, not a single expression.
If you write
foo = {a, b, c}
x = foo{:}
This is equivalent to
foo = {a, b, c}
x = foo{1}, foo{2}, foo{3}
but the results of the expressions foo{2} and foo{3} are not printed.
FWIW, this behavior is compatible with Matlab, and we have this syntax
and semantics for compatibility with Matlab; we did not invent it
solely to confuse you.
| I.e. why for arithmetic expressions in case of "sizeof(1 + 2)" I see
| something like:
|
| invisible_result = 1 + 2; sizeof(invisible_result)
Because 1+2 is an expression that produces a single value.
| but for comma-separated list in case of "sizeof(foo{:})" I do _not_ see
|
| invisible_result = foo{:}; sizeof(invisible_result)
Because, assuming that foo in the expression above is a cell array,
the expression
invisible_result = foo{:}
is equivalent to writing
invisible_result = foo{1}, foo{2}, ..., foo{end}
and
sizeof (foo{:})
is equivalent to
sizeof (foo{1}, foo{2}, ..., foo{end})
but sizeof does not accept multiple arguments, so it is an error to
call it this way.
jwe
- foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{:}), Sergei Steshenko, 2011/08/08
- Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{:}), Sergei Steshenko, 2011/08/08
- Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{:}),
John W. Eaton <=
- Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{:}), Sergei Steshenko, 2011/08/08
- Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{:}), Jordi GutiƩrrez Hermoso, 2011/08/08
- Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{:}), Przemek Klosowski, 2011/08/08
- Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{:}), Sergei Steshenko, 2011/08/09
- Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{:}), James Sherman Jr., 2011/08/08
- Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{:}), Ben Abbott, 2011/08/08
Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{:}), Sergei Steshenko, 2011/08/09