Path: news.mathworks.com!not-for-mail
From: "Mahdieh" <mahdieh.emrani@capitalhealth.ca>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to do vectorize this simple code?
Date: Fri, 14 Nov 2008 23:17:03 +0000 (UTC)
Organization: Glenrose Research Building
Lines: 22
Message-ID: <gfl0tf$srs$1@fred.mathworks.com>
References: <gfkstu$1id$1@fred.mathworks.com>
Reply-To: "Mahdieh" <mahdieh.emrani@capitalhealth.ca>
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 1226704623 29564 172.30.248.38 (14 Nov 2008 23:17:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 14 Nov 2008 23:17:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1449772
Xref: news.mathworks.com comp.soft-sys.matlab:500925


"Henry " <henry@fullspectrumengineering.com> wrote in message <gfkstu$1id$1@fred.mathworks.com>...
> I want to vectorize this simple snippet:
> 
> for i=1:num_elements
>     y(i)=my_matrix(row(i),col(i));
> end
> 
> I tried y=my_matrix(row,col)
> and y=my_matrix([row col])
> 
> but nothing seems to work.  Any pointers?  Thanks.

Hi Henry

I guess this works:

U = mymatrix(row,:);
V = U(:,col);
y = diag(V);

-Mah