[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: no way for simple matrix lookup ?
From: |
Etienne Grossmann |
Subject: |
Re: no way for simple matrix lookup ? |
Date: |
Wed, 16 Jun 2004 15:32:22 -0400 |
User-agent: |
Mutt/1.4.2.1i |
A = reshape (1:60,3,5,4);
b = ones(5,1)*[2 3 1 2 3 1]; # Quintiplate all indexes
c = ones(5,1)*[4 1 2 3 4 1]; # idem
d = [1:5]'*ones(1,6); # Run indexes
D = A(sub2ind (size (A),b, d, c))
Seems correct
On Wed, Jun 16, 2004 at 03:08:22PM -0400, D. Goel wrote:
# Etienne Grossmann <address@hidden> writes:
#
# > A = reshape (1:12, 3,4);
# >
# > b = [2 3 1 2 3];
# > c = [4 1 2 3 4];
# >
# > D = A(sub2ind (size (A),b, c))
# >
# > D = diag (A(b,c)) # Don't do that
# >
#
#
# Many thanks to Etienne for the above solution, and to everyone else
# for similar solutions. Anyone have any ideas on the question below
# (which is the actual problem at hand) -->
#
# > #
# > # [3] More generally, the problem i am struggling with is:
# > #
# > # A is a nxmxl matrix. b and c are vectors.
# > # I am looking for a vector D, such that D(i,:)= A(b(i), :, c(i)).
# > #
# > # Any way to do that?
#
#
#
#
--
Etienne Grossmann ------ http://www.cs.uky.edu/~etienne