Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: find elements to include page indices
Date: Thu, 24 Jul 2008 09:07:22 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 51
Message-ID: <g69goa$bud$1@fred.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>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1216890442 12237 172.30.248.37 (24 Jul 2008 09:07:22 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 24 Jul 2008 09:07:22 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1338633
Xref: news.mathworks.com comp.soft-sys.matlab:481459



"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.