Path: news.mathworks.com!not-for-mail
From: "Michael Lonther" <rsbu@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: faster for loop
Date: Thu, 13 Nov 2008 15:48:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 22
Message-ID: <gfhi7j$str$1@fred.mathworks.com>
Reply-To: "Michael Lonther" <rsbu@yahoo.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1226591283 29627 172.30.248.35 (13 Nov 2008 15:48:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 13 Nov 2008 15:48:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1259131
Xref: news.mathworks.com comp.soft-sys.matlab:500644


Hello,
I would greatly appreciate if there is a non-FOR-loop version of this code.  It is very slow because I think it is very inefficient.  Thank you..

% aggregate irr data to GADM values
fid = fopen('file1.bin','rb');
irrarea = fread(fid,'float');
fclose(fid);
clear fid;
fid = fopen('file2.bin','rb');
gadm = fread(fid,'float');
fclose(fid);
clear fid;

num = unique(sort(gadm));
num(1) = [];

irrmean = zeros(4320*2160,1);
for i = 1:length(num)
    a = find(gadm == num(i));
    irrmean(a) = mean(irrarea(a));
    clear a;
end