Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!news.glorb.com!postnews.google.com!b14g2000yqd.googlegroups.com!not-for-mail
From: Rune Allnor <allnor@tele.ntnu.no>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Vectorization
Date: Sun, 5 Jul 2009 05:05:03 -0700 (PDT)
Organization: http://groups.google.com
Lines: 25
Message-ID: <16ef8c3f-f634-440c-8d30-8b1d639cf30d@b14g2000yqd.googlegroups.com>
References: <8d98157c-ab47-40cb-8e4f-af119371a0db@h8g2000yqm.googlegroups.com>
NNTP-Posting-Host: 77.16.131.111
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1246795505 2034 127.0.0.1 (5 Jul 2009 12:05:05 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 5 Jul 2009 12:05:05 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: b14g2000yqd.googlegroups.com; posting-host=77.16.131.111; 
	posting-account=VAp5gAkAAAAmkCze5hvZtMeedpZWNthI
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; 
	Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 
	3.5.21022),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:552874


On 4 Jul, 22:24, laxxy <laxyf...@gmail.com> wrote:
> Hi all --
>
> I am wondering if it is possible to eliminate the loop in the
> following piece of code:
>
> for i=1:K
>   W(i,:) = Q(i,:)*V(:,P(i,:));
> end;
>
> (that is: each row i of the result is computed by multiplying ith row
> of matrix Q by a permutation of columns of V specified by the i'th row
> of P).
>
> Here Q is a KxK square matrix; and all other matrices are KxN. P is an
> existing index matrix containing indices into columns of V.
>
> I've tried a few things but so far have not had too much success... :(

What about

W(1:K,:) = Q(1:K,:)*V(:,P(1:K,:));

Rune