[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: element extraction from vector
From: |
Jaroslav Hajek |
Subject: |
Re: element extraction from vector |
Date: |
Sun, 27 Dec 2009 07:15:16 +0100 |
On Sun, Dec 27, 2009 at 1:20 AM, <address@hidden> wrote:
> Hi the Octavers,
> I would like to ask you: if we have a vector u of this form:
> u=[1 0 0 0 0 -1 0 0 0 0 0 1]';
> How we can construct a program that extract two vectors v and w from u, where
> the elements of v are 1 and -1, i.e v=[1,-1,1]', and the elements of w are
> the number of observations of the elements of v in u, i.e w=[1 6 12]'.
> Many thanks in advance.
> Hassen.
>
>
> ____________________________________________________
>
> Tables en fĂȘte, recettes parfaites, sorties en goguette tout est sur
> http://evenementiel.voila.fr/Noel
>
Use "find".
[xxx, w, v] = find (u);
OR
w = find (u); v = u(w);
hth
--
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz