Loop vectorization

IDSTAT-29
TitleVectorize loops where feasible.
PriorityStrongly recommended
Severity level6
DescriptionInstead of looping over the elements of arrays, apply operations to them in their entirety. Use scalar and implicit expansion, if applicable.
RationaleVectorized loops are faster, more robust, more readable, and more maintainable.

Avoid:

dataResult = false(size(dataset));

for iElem = 1 : numel(dataset)
    if dataset(iElem) < limit(iElem)
        dataResult(iElem) = true;
    else
        dataResult(iElem) = false;
    end
end

Instead use:

dataResult = dataset < limit;