Path: news.mathworks.com!not-for-mail
From: "James Wright" <jameswright1001@yahoo.co.uk>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Help speeding up/replacing loops
Date: Wed, 17 Jun 2009 16:20:19 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 23
Message-ID: <h1b543$gj9$1@fred.mathworks.com>
References: <h18ge7$gta$1@fred.mathworks.com>
Reply-To: "James Wright" <jameswright1001@yahoo.co.uk>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1245255619 17001 172.30.248.38 (17 Jun 2009 16:20:19 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 17 Jun 2009 16:20:19 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1878517
Xref: news.mathworks.com comp.soft-sys.matlab:548358


Maybe finding a way to vectorize that isn't worth the time it'll take. The main time consumer is most probably this loop anyway.

    for f = 1:g
        p = cumsum(B(1:N).*cos((1:N)*C(f)));
        q = cumsum(B(1:N).*sin((1:N)*C(f))); 
        %calculates the m(n)s for the range of c
        for n = 1:ncut
            m(n) = sum((p((n+1):N)-p(1:(N-n))).^2+(q((n+1):N)-q(1:(N-n))).^2);
            m(n) = (m(n))/(N-n);
        end
        %calculates the oscillatory terms
        Vosc(1:n) = (E^2)*((1-cos((1:ncut)*C(f)))/(1-cos(C(f))));
        %Works out the new meansquare displacement with the oscillating
        %term taken out
        D(1:ncut) = m(1:ncut) - Vosc(1:ncut);
        %creates a vector containing the values of k for each value of c
        K(f) = corr(X,D);
    end


However, is it possible to vectorize this further? As the loops already contain vectorizations. I imagine this would also make things extremely complicated.

Thanks for all the help so far!