[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Accessing information returned from 'dir'
From: |
John W. Eaton |
Subject: |
Re: Accessing information returned from 'dir' |
Date: |
Thu, 7 Oct 2004 09:24:54 -0400 |
On 6-Oct-2004, address@hidden <address@hidden> wrote:
| There are two possibilities, and in my opinion, Matlab has chosen the
| wrong one. You *should* be able to make a cross-section in a cell array
| and expect the result to behave like another cell array.
That is what indexing with () is for. It extracts sub-arrays. Note
that if only a single element is selected, it is still returned as a
cell array:
octave:1> x = {1,2;3,4}
x =
{
[1,1] = 1
[2,1] = 3
[1,2] = 2
[2,2] = 4
}
octave:2> x(1)
ans =
{
[1,1] = 1
}
octave:3> typeinfo (x(1))
ans = cell
| While on topic, what is the reason for accessing cell arrays with {}?
Indexing with {} returns individual objects. Note the difference from
the previous example:
octave:4> x{1}
ans = 1
octave:5> typeinfo (x{1})
ans = scalar
If more than one object is selected by {} indexing, it is returned as
a comma-separated list, which can be used in certain other contexts as
if it were a list of arguments, or a list of elements to construct a
matrix or cell array. For example,
sum (x{:}) ## sum elements of X
[x{:}] ## same as [x{1}, x{2}, ..., x{end}]
{x{:}} ## same as {x{1}, x{2}, ..., x{end}}
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
-------------------------------------------------------------