How to find the position of the first non-zero element of my matrix?

49 views (last 30 days)
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?

Accepted Answer

Stephen23
Stephen23 on 10 Mar 2020
Edited: Stephen23 on 10 Mar 2020
find(yourVector,1,'first')

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!