function output=leastnonzero(array) % This function finds the least non-zero value given an array. % For example, % x=[ 3 2 1; -1 3 -5]; % y=leastnonzero(x) % % output: y=1 % Author: David Li % Date: April 28, 2005 [n m]=size(array); input=reshape(array,n*m,1); input=sort(input); while(min(input)<=0) if (max(input)<=0) break end input=input(2:end); end output=min(input);