MATLAB: How to find the position of the first non-zero element of the matrix

element positionMATLABmatrix

For example, if I have a column data like the below:
A = [0; 1; 0; 0; 0];
The answer would be 2.
For the below example:
B = [ 0; 0; 1; 0; 1; 0; 0];
The answer would be 3.
Is there a function to do that quickly?

Best Answer

find(yourVector,1,'first')