[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: indexing cell arrays
From: |
Jaroslav Hajek |
Subject: |
Re: indexing cell arrays |
Date: |
Sat, 6 Jun 2009 20:27:20 +0200 |
On Sat, Jun 6, 2009 at 8:05 PM, Thorsten Meyer<address@hidden> wrote:
> Hi,
>
> Jaroslav Hajek wrote:
>
> On Sat, Jun 6, 2009 at 4:19 PM, Thorsten Meyer<address@hidden>
> wrote:
>
>
> Hi,
>
> While working on the documentation of container types, I found that it is no
> longer possible to assign to a subarray of cell array c like this:
> c{:,2} = 1
>
>
> Yes. The correct way is c(:,2) = {1}. I think c(:,2) = 1 still works
> as well. But c{:,2} was surely wrong, because it produces a cs-list
> (and thus represents a sequence of lvalues rather than one).
>
>
> Also, in the manual, there is an (obsolete) example that shows how to set
> elements of a cell array to [] with
> c{:,2}= [] (generates an error in octave 3.1!)
> and eliminate elements with
> c(:,2) = []
>
> I found, that the first of the two can now be achieved by
> c(:,2) = {[]}
> And the second still works, as does
> c(:,2) = 3
>
> So a scalar gets promoted to a cell array with one entry, while the
> null_matrix has the special meaning of eliminating entries in a cell array
> (and other array types).
>
> Is this consistent with matlab?
>
Yes, AFAIK. I think we deliberately allowed the promotion (which
Matlab doesn't) because it is not ambiguous, to keep a bit of bkw
compatibility. But this can still be revised, and c(:,2) = {3} is
probably the preferred way.
--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz