MATLAB: Extract the min of nonzero

except for zerosmin abs valueprogramming

Hi, I am trying to extract the non zero minumun out of 6*4 matrix
M =
0.1183 0 0.1183 0
-0.0931 -0.0931 0 0
0 1.0172 0 1.0172
0.1510 0 0 0.1510
0 0.9385 0.9385 0
0 0 0.9823 0.9823
min(abs(M(M(:,i)~=0))) where i = 1:4 // this is supposed to extract the minmum of absolute value in the each column
First column shows the right result, from second row, it gives me all zero.

Best Answer

A trick is to set the zeros to infinity and then do it:
M = [...
0.1183 0 0.1183 0
-0.0931 -0.0931 0 0
0 1.0172 0 1.0172
0.1510 0 0 0.1510
0 0.9385 0.9385 0
0 0 0.9823 0.9823]
% Set zeros to infinity so they won't be considered:
M(M==0) = inf;
columnMins = min(abs(M), [], 1)