Programming and Data Types | ![]() ![]() |
Program 3b -- Vector Comparison, Vectorized
Here is the vectorized version of the same program. Note that there is little difference in performance between the accelerated while
loop, shown in "Program 3a", and the vectorized code shown below. This means that, with accelerated MATLAB, you have the freedom to choose the style of coding that you prefer for each MATLAB application without affecting performance.
The table below also shows little difference in the times measured for running the vectorized code on unaccelerated and accelerated versions of MATLAB. You will not see a significant performance improvement in vectorized programs when run with the accelerator.
Operating System |
MATLAB 6.1 |
MATLAB 6.5 |
Performance Gain |
Windows |
0.7 sec. |
0.6 sec. |
x 1.2 |
Linux |
1.0 sec. |
0.9 sec. |
x 1.1 |
Solaris |
1.2 sec. |
1.2 sec. |
x 1.0 |
Here is the vectorized version of the vfind
program:
function [aIndex, bIndex] = vfind_vector(avec, bvec) avecLen = length(avec); bvecLen = length(bvec); avec = reshape(avec, avecLen, 1); bvec = reshape(bvec, bvecLen, 1); [c, pc] = sort([avec; bvec]); cIndex = find(diff(c) == 0); aIndex = pc(cIndex); bIndex = pc(cIndex + 1) - avecLen;
![]() | Program 3a -- Vector Comparison, with Loop | Program 4 -- Tic-Tac-Toe | ![]() |