Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: find elements to include page indices
Date: Wed, 23 Jul 2008 13:17:19 -0400
Organization: The MathWorks, Inc.
Lines: 49
Message-ID: <g67p2v$hkg$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: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1216833439 18064 144.212.105.187 (23 Jul 2008 17:17:19 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 23 Jul 2008 17:17:19 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
Xref: news.mathworks.com comp.soft-sys.matlab:481291




"Dave Brackett" <davebrackett@hotmail.com> wrote in message 
news: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].

If the two matrices (the one from which you extract the locations and the 
one into which you want to index) are the same size, don't convert the 
linear indices into subscripts -- just use the linear indices directly.

If the two matrices are _not_ the same size, then I'd think a bit more about 
the problem.  That seems to me to be an apples and oranges type of 
situation.

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

You're performing linear indexing into b.  The result you get out is the 
same size and shape as the matrix of indices.

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

The former is subscripted indexing.  The latter is linear indexing.

-- 
Steve Lord
slord@mathworks.com