From: "Jonny O'Connell" <>
Newsgroups: comp.soft-sys.matlab
Subject: Vectorization Help...I think
Date: Sat, 17 Jul 2010 18:06:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 20
Message-ID: <i1sreb$6fs$>
Reply-To: "Jonny O'Connell" <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1279389963 6652 (17 Jul 2010 18:06:03 GMT)
NNTP-Posting-Date: Sat, 17 Jul 2010 18:06:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2413904
Xref: comp.soft-sys.matlab:653919


I'm really new to MALTAB, I only sat the module this semester, but somehow I've managed to get myself a summer project writing a parallel evolutionary algorithm in it! 

Anyway I've done some basic profiling on my code and found that one line is accounting for about ~45% of my run time. It's a find function, but it's pretty much a copy and paste from the help documentation (obviously adapted for my needs), but I'm not sure if I can improve it any further.

From the literature I've read on MATLAB, vectorization is king, and should be used anywhere it can be for better performance. I've had some success on various parts of the program, but I'm not sure if what I have is a candidate for vectorization and I was hoping someone could cast an experienced eye over it.

% Perform swapping until cycle is complete
    while cycleIndex ~= seedNumber;
        cycleIndex = find(firstParent == secondParent(currentNumber));
        offspring(cycleIndex) = firstParent(cycleIndex);
        currentNumber = cycleIndex;

The culprit is the 'find' line, the first line in the loop. 

Any pointers would be good!