MATLAB: Extract the first negative value in a matrix column

findmatrixnegative values

I have a 501×100000 Matrix, containing positive and some negative values. The values were calculated using random numbers. I need the value, not the index of the first negative entry in each column. If there is no negative value in the column it should be displayed by a 0.
simplified example:
A = [ 1, 2, 5, 6; -1, 4, 8,-4; -2, 3, 9, 1; -2,-1, 3,-1 ]
The answer I need (for that example) is:
-1,-1,0,-4
Thanks in advance for any help…

Best Answer

Edit
out=arrayfun(@(x) min([ 0 A(find(A(:,x)<0,1),x)]),1:size(A,2))