Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: faster sqi-squared calculation needed
Date: Wed, 23 Mar 2011 14:49:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 13
Message-ID: <imd190$arp$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1300891745 11129 172.30.248.48 (23 Mar 2011 14:49:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 23 Mar 2011 14:49:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2761202
Xref: news.mathworks.com comp.soft-sys.matlab:717663

Is there any way to make the codes below faster? mat is a feature by record matrix, gamma is returned as the result of one over average sqi-squared distance. The matrix is big, 4k x 10k. Thanks in advance.

function gamma = chisq(mat)

allcol  = size(mat, 2);
total   = 0;
for col =1:allcol-1
        D = (repmat(mat(:,col),1,allcol-col)-mat(:,col+1:end)).^2./(repmat(mat(:,col),1,allcol-col)+mat(:,col+1:end));
        D(isnan(D)) = 0;
        total = total + sum(sum(D));
end

gamma = (2*allcol-3) / total;