What does the command A(~A) really do in matlab -
i looking find efficient way find non 0 minimum of matrix , found on forum :
let data matrix a.
a(~a) = nan; minnonzero = min(a); this short , efficient (at least in number of code lines) don't understand happens when this. can't find documentation since it's not operation on matrices +,-,\,... be.
could explain me or give me link or me understand done ? thank !
it uses logical indexing
~ in matlab not operator. when used on double array, finds elements equal zero. e.g.:
~[0 3 4 0] results in logical matrix
[1 0 0 1] i.e. it's quick way find 0 elements
so if a = [0 3 4 0] ~a = [1 0 0 1] a(~a) = a([1 0 0 1]). a([1 0 0 1]) uses logical indexing affect elements true in case element 1 , element 4.
finally a(~a) = nan replace elements in equal 0 nan min ignores , find smallest non-zero element.
Comments
Post a Comment