help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: indexing struct


From: Jaroslav Hajek
Subject: Re: indexing struct
Date: Tue, 27 Apr 2010 14:51:55 +0200

On Tue, Apr 27, 2010 at 2:34 PM, Mike B. <address@hidden> wrote:
> Hi All,
>
> Is it possible to loop over a struct with indexing?
>
> For example:
> a( 1 ).vec = [ 1, 2, 3 ];
> a( 2 ).vec = [ 4, 5, 6 ];
>
> For all structure cells I'd like to get the 1st vector component, so this 
> should give
> 1 4
>
> but
>
> a( : ).vec( 1 ) gives
>
>> error: can't perform indexing operations for cs-list type
>

Yes, cs-lists (such as a(:).vec) can't be further indexed (for good
reasons). You have several options to achieve the goal, for instance,
if all your vectors are of the same length, you can do:
vertcat (a.vec)(:, 1)


-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

[Prev in Thread] Current Thread [Next in Thread]