MATLAB: How to find the column number of first zero element of each row

matrix manipulationvectorization

Hi,all. could you please tell me how to find the column number of first zero element of each row. eg. for the matrix in the picture, I want the output will be outputmatrix=[3;4;4;5;5;6;6;6;6;6;1;1;1;1;1]. Thank you!

Best Answer

This is your answer:
a =[ -1 3 0 0 0 0
2 3 4 5 0 0
1 2 1 0 0 0]
b = abs(a); % it is a trick which forces min to do not consider your negative numbers as minimum
[~,ind] = min(b')