I use some weighted probability routines and the following code is to slow. Is there a way to optimize it? I already preallocated everything.
function normalizedFrame = normalizer (currentFrame, normalizedFrame, oneLevelFrame, dataCube, maxADU) %#codegen
%
for i = maxADU:-1:1 oneLevelFrame(currentFrame==i) = 1; dataCube(:,:,i) = oneLevelFrame; oneLevelFrame = zeros(31, 31); currentFrame(currentFrame==i) = currentFrame(currentFrame==i)-1;end%possitionsIn3dCube = find(dataCube);[row, col, ~] = ind2sub(size(dataCube), possitionsIn3dCube);index = randi(length(row));photonPossition = [row(index), col(index)];normalizedFrame(photonPossition(1), photonPossition(2)) = 1;
Best regards, Alex
Best Answer