help-octave
[Top][All Lists]

## product of empty vectors

 From: John W. Eaton Subject: product of empty vectors Date: Fri, 23 May 2003 16:20:41 -0500

```On 23-May-2003, Douglas Harder <address@hidden> wrote:

| Octave's handling of empty matrices is a little odd:
|
| >> a = 1:2
| a =
|   1  2
| >> a(1:0)
| ans = []
| >> ans * ans'   % this should be 0
| ans = []
| >> ans + 3
| ans = []

The only real problem here is that Octave interprets 1:0 as a 0x0
empty matrix instead of a 1x0 empty matrix.  Should we change that?

If you actually generate a 1x0 matrix, the rest works as you expect:

octave:1> x = zeros (1,0)
x = [](1x0)
octave:2> x*x'
ans = 0

Likewise, the indexing works as you expect:

octave:3> a = 1:2
a =

1  2

octave:4> a(x)
ans = [](1x0)

and of course 0+3 == 3.

| Hopefully this wasn't a design decision in Octave to convert all
| empty matrices to 0x0.

No.  In fact, Octave had empty matrices with nonzero dimensions before
Matlab.

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

```