Path: news.mathworks.com!not-for-mail
From: "Jerry" <mricad@yahoo.no000spppam.com>
Newsgroups: comp.soft-sys.matlab
Subject: Vectorization of matrix operations--need guru's help!
Date: Mon, 24 Nov 2008 17:59:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 15
Message-ID: <ggeq17$hj$1@fred.mathworks.com>
Reply-To: "Jerry" <mricad@yahoo.no000spppam.com>
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 1227549543 563 172.30.248.37 (24 Nov 2008 17:59:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 24 Nov 2008 17:59:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 544673
Xref: news.mathworks.com comp.soft-sys.matlab:502877


is there any way to improve the speed of the following code? I need to call it 10000 times. thanks!

function m4=calm4(mwk)
[n0,n1]=size(mwk);
m4=0;
for i=1:n0
    tmp1=mwk(:,i);
    for ii=1:n0
        if ii~=i
            tmp2=mwk(:,ii)*tmp1';
            m4=m4+sum(sum(tmp2))-sum(diag(tmp2));
        end
    end
end
m4=m4/(n0*n1*(n0-1)*(n1-1));