Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: vectorization - speed up
Date: Tue, 3 Mar 2009 09:55:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 27
Message-ID: <goiupn$6c8$1@fred.mathworks.com>
Reply-To: <HIDDEN>
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 1236074104 6536 172.30.248.35 (3 Mar 2009 09:55:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 3 Mar 2009 09:55:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1612112
Xref: news.mathworks.com comp.soft-sys.matlab:522068


Hello.
I need to speed up this function.
It is executed many times in my algorithm and it runs on big matrix.
I have used the profiler and it is the most called and the most time consuming function.
Any help would be appreciated.

function Singleton = singleton(classes, Parameters, ImageMatrix)
global HSV_rows HSV_cols

Singleton = cell(1,classes);
for l=1:classes
    temp = zeros(HSV_rows, HSV_cols);
    detSl = Parameters(l).DetermS;
    temp2 = -log(1/(sqrt(power(2*pi,3)*detSl)));
    Ml = Parameters(l).Med;
    invSl = Parameters(l).InverS;
    for r=1:HSV_rows
        for c=1:HSV_cols
            fl = double(cell2mat(ImageMatrix(r,c)));
            temp(r,c) = (fl - Ml) * invSl * (fl - Ml)';
        end
    end
    Singleton{l} = real(temp2+temp*.5);
end

Thank you very much in advance for any kind of help,
Francesco