|
Thanks Jos and Brett, this is exactly what I needed
"Brett Shoelson" <bshoelso@mathworks.com> wrote in message <gri808$15g$1@fred.mathworks.com>...
> More to the point, Yoav, what the "ok==1" does in Jos's code is convert the
> 1/0 indices in ok to logicals:
>
> >> class(ok)
> ans =
> double
> >> class(ok==1)
> ans =
> logical
>
> Once you have a logical array, you can use it to do logical indexing. Which
> is one of the key features of MATLAB, imho. :)
>
> So alternatively,
>
> >> gooddata = data(logical(ok))
> gooddata =
> 12 13 10 8
>
> HTH,
> Brett
>
> "Jos " <#10584@fileexchange.com> wrote in message
> news:gri6p9$6lg$1@fred.mathworks.com...
> > "Yoav Rubin" <yoavrubin@hotmail.com> wrote in message
> > <gri62q$hhd$1@fred.mathworks.com>...
> >> Hi all,
> >>
> >> I have two vectors, one with data, and one with 0 /1 values that says
> >> which items on the first vector are valid. I need to create a third
> >> vector that is built only from the valid items on the first vector. Is
> >> there a single command that does that (it's easy to do it iteratively,
> >> but I guess that the performance are bad doing it like that)
> >>
> >> thanks
> >>
> >> Yoav
> >
> > This is called logical indexing and is one of the key features of matlab
> > (imho).
> >
> > data = [12 13 5 10 7 8 9]
> > ok = [1 1 0 1 0 1 0]
> >
> > gooddata = data(ok==1) ;
> > % Another example of logical indexing:
> > largedata = data(data>10)
> >
> > hth
> > Jos
>
|