Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!b40g2000prf.googlegroups.com!not-for-mail
From: KC <kc_news@sonic.net>
Newsgroups: comp.soft-sys.matlab
Subject: vectorization help
Date: Mon, 19 Nov 2007 22:15:33 -0800 (PST)
Organization: http://groups.google.com
Lines: 22
Message-ID: <26726115-2bc1-4fc2-8ce2-7b5a4d1178a1@b40g2000prf.googlegroups.com>
NNTP-Posting-Host: 71.105.90.133
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1195539333 28846 127.0.0.1 (20 Nov 2007 06:15:33 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 20 Nov 2007 06:15:33 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: b40g2000prf.googlegroups.com; posting-host=71.105.90.133; 
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) 
Content-Disposition: inline
Xref: news.mathworks.com comp.soft-sys.matlab:438462



This code takes for ever (well not really, but longer than I think it
should) to run... I can't figure out how to speed it up... any help?
I'm trying to learn vectorization techniques, but I don't see how
vectorization can be applied here.  Can it?

%% Define angle vectors
x = avgang(:,1);
y = avgang(:,2);
[r,c]=size(angs{1,1});
%% loop
for n = 1:r;
dist(:,n) = sqrt((x-angs{1,1}(n,1)).^2 + (y-angs{1,2}(n,1)).^2);
[minDist(n,1), minDist(n,2)] = min(distVectors(:,n));
%second column is the index number
end

FYI, "angs" is a 1x3 cell (but I only care about cells 1 & 2 for now),
and each cell is a 1001x9 double.  "avgang" is a 1001x3 array, and I
only care about columns 1 & 2 for now.

Thanks for any help.
-Kieran