Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: find elements to include page indices
Date: Wed, 23 Jul 2008 17:15:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 41
Message-ID: <g67oup$fhu$1@fred.mathworks.com>
References: <g677t2$j92$1@fred.mathworks.com> <g67c9g$lsl$1@fred.mathworks.com> <g67foc$92q$1@fred.mathworks.com> <g67hkb$5bl$1@fred.mathworks.com> <g67lt6$4c9$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1216833305 15934 172.30.248.38 (23 Jul 2008 17:15:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 23 Jul 2008 17:15:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1215962
Xref: news.mathworks.com comp.soft-sys.matlab:481290



"Dave Brackett" <davebrackett@hotmail.com> wrote in message
<g67lt6$4c9$1@fred.mathworks.com>...
> > i believe you have your inputs to the ind2sub switched: the
> > first argument is the size and the second argument are the
> > values you're interested in.
> 
> ah yeah, thanks. I can now get the subscripts and have
> assigned them to a variable, a, which is then of the size
> [788 3] with rows like:
> 
> [1 2 1;
>  1 6 1;
>  1 9 1;
>  1 10 1;
>  1 11 1;
>  1 12 1;
>  ...etc]
> 
> I want to use the indices at each row to extract the
> corresponding elements from another matrix, b, which is of
> the size [90 16 50].
> 
> I tried to implement this as simply c=b(a) but I get c as of
> the size [788 3] whereas it should be of the form [90 16 50].
> 
> If I write c=b(1,2,1) I can get a single element, but if i
> write c=b([1 2 1]) i get 3 elements. Why is there a
> difference between these 2 methods? I think this might be
> the cause of this problem.
> 
> Thanks
> 

when you access it in the second way, you're getting the
matrix b at the linear indices 1, 2, and 1. Your output will
be something like [num1 num2 num1]. Instead, you should
access it via the linear indices (the ones you found BEFORE
passing to ind2sub). if you use those indices and the
c=b([linearindices]) notation, it should work.