MATLAB: How to vectorize this code to eliminate nested For loops

for loopvectorization

Would like to know how this code be vectorized:
for y=1:rows
for x=1:cols
nEnergy(y,x) = (Energy(y,x) - min(Energy)) / (max(Energy) - min(Energy));
end
end
for y=1:rows
for x=1:cols
weight(y,x) = dot(nEnergy(y,x), delta(y,x));
end
end
nEnergy, weight, delta is an array.

Best Answer

Assuming that the first set of loops is supposed to normalize the data:
nEnergy = (Energy-min(Energy(:))) / (max(Energy(:))-min(Energy(:)));
w1 = delta.*nEnergy
Related Question