[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Structure items as vectors?
From: |
David Bateman |
Subject: |
Re: Structure items as vectors? |
Date: |
Mon, 14 Apr 2008 12:03:50 +0200 |
User-agent: |
Thunderbird 2.0.0.12 (X11/20080306) |
Schirmacher, Rolf wrote:
> Hello,
>
> I want to use structured information for numerical computations. I have a
> structure like
>
> octave.exe> some.data.structure(1).item = 1;
> octave.exe> some.data.structure(2).item = 2;
>
> and later on, I want to do calculations with a vector of "item"s. What I get
> is a list like
>
> octave.exe> some.data.structure.item
> ans =
>
> (,
> [1] = 1
> [2] = 2
> ,)
>
> octave.exe> some.data.structure(:).item
> ans =
>
> (,
> [1] = 1
> [2] = 2
> ,)
>
>
> On the other hand, I can access the individual elements as scalars like
>
> octave.exe> some.data.structure(1).item
> ans = 1
>
>
> How can I retrive the data as a vector, i.e. overcome such errors most
> easily?
>
> octave.exe> items_doubled = 2 .* some.data.structure(:).item
> error: binary operator `.*' not implemented for `scalar' by `cs-list'
> operations
> error: evaluating binary operator `.*' near line 59, column 19
> error: evaluating assignment expression near line 59, column 15
>
>
The returned value above is a comma-separated list in exactly the same
manner as Matlab returns the above. Try "[some.data.structure.item]",
which converts your comma seperated list into a matrix. Or if you can't
be sure the data is numeric, try "{some.data.structure.item}" which
converts it to a cell array.
D.
--
David Bateman address@hidden
Motorola Labs - Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob)
91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax)
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary