help-octave
[Top][All Lists]
Advanced

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

Re: indexing struct


From: Mike B.
Subject: Re: indexing struct
Date: Tue, 27 Apr 2010 19:14:53 -0700 (PDT)

Thanks Jaroslav, works great.

--- On Tue, 27/4/10, Jaroslav Hajek <address@hidden> wrote:

> From: Jaroslav Hajek <address@hidden>
> Subject: Re: indexing struct
> To: address@hidden
> Cc: "Octave mai. lis." <address@hidden>
> Date: Tuesday, 27 April, 2010, 10:51 PM
> 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]