I have a 3D matrix, and I would like to find the index to the minimum value along the 3rd dimension. In other words, I would like to replace the following loop with a faster operation:
A = rand(10,8,3);indexToMinIn3rdDim = NaN*ones(size(A,1), size(A,2)); for iRow = 1:size(A,1) for iCol = 1:size(A,2) indexToMinInVector = find((squeeze(A(iRow,iCol,:))) == min((squeeze(A(iRow,iCol,:))))); indexToMinInVector = indexToMinInVector(1); % Only keep 1st index if the same min value occurs
indexToMinIn3rdDim(iRow,iCol) = indexToMinInVector; endend
Best Answer