Path: news.mathworks.com!not-for-mail
From: Loren Shure <loren@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: find elements to include page indices
Date: Thu, 24 Jul 2008 08:08:16 -0400
Organization: The MathWorks
Lines: 64
Message-ID: <MPG.22f23aba4a2a779898989a@news.mathworks.com>
References: <g677t2$j92$1@fred.mathworks.com> <g69cqo$gsb$1@fred.mathworks.com> <g69e92$js4$1@fred.mathworks.com> <g69eo0$ntt$1@fred.mathworks.com> <g69goa$bud$1@fred.mathworks.com>
NNTP-Posting-Host: shurel.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-15"
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1216901296 1920 172.31.57.117 (24 Jul 2008 12:08:16 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 24 Jul 2008 12:08:16 +0000 (UTC)
User-Agent: MicroPlanet-Gravity/2.70.2067
Xref: news.mathworks.com comp.soft-sys.matlab:481496



In article <g69goa$bud$1@fred.mathworks.com>, davebrackett@hotmail.com 
says...
> "us " <us@neurol.unizh.ch> wrote in message
> <g69eo0$ntt$1@fred.mathworks.com>...
> > "Dave Brackett":
> > <SNIP simple question...
> > 
> > > ok, and then how can I find the elements of another matrix
> > > using the indices from this result...
> > 
> > ...one of the (simple) solutions
> > 
> > % the data
> >      m=zeros([2,3,4]);
> >      m(1,1,1)=nan;
> >      m(2,2,3)=nan;
> >      m(2,3,4)=nan;
> > % the engine
> >      lix=find(m);
> >      ix=cell(1,ndims(m));
> >      [ix{1:end}]=ind2sub(size(m),lix);
> >      r=cat(2,ix{:});
> > % the result
> >      disp(r);
> > %{
> >      1 1 1
> >      2 2 3
> >      2 3 4
> > %}
> > 
> >      m(isnan(m))=-1;
> >      lix=sub2ind(size(m),ix{:});
> >      r=m(lix);
> >      disp(r);
> > %{
> >      -1
> >      -1
> >      -1
> > %}
> > 
> > us
> 
> 
> Ok I think i may have missed out a crucial bit of info to
> achieve what I want, so for clarity to summarise, I want to:
> 1) get the positions of non 0 values from x
> 2) use these positions to find the corresponding elements of
> b but retain their relative positions, with all other
> elements replaced by zeros.
> 
> If possible, I would prefer to use the non-cells method from
> earlier in this thread. Thanks for all your help guys.
> 
> 

I think you're saying that where x is 0 you want b to also be 0. If 
that's true, here goes:

logind = (x==0);
b(logind) = 0;

-- 
Loren
http://blogs.mathworks.com/loren/