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

414 vues (au cours des 30 derniers jours)
Leon
Leon le 10 Mar 2020
Commenté : Leon le 10 Mar 2020
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?

Réponse acceptée

Stephen23
Stephen23 le 10 Mar 2020
Modifié(e) : Stephen23 le 10 Mar 2020
find(yourVector,1,'first')

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by