Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to do vectorize this simple code?
Date: Fri, 14 Nov 2008 22:18:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 4
Message-ID: <gfktep$9al$1@fred.mathworks.com>
References: <gfkstu$1id$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1226701081 9557 172.30.248.37 (14 Nov 2008 22:18:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 14 Nov 2008 22:18:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1601482
Xref: news.mathworks.com comp.soft-sys.matlab:500917


If I understand you correctly, all you need is the diagonal. I believe this is the simplest way (at least that I'm aware of).

y(i)=diag(my_matrix(row(i),col(i)));