Finding column index of the first instance of 1
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Pelajar UM
il 2 Mag 2022
Commentato: Walter Roberson
il 3 Mag 2022
I have a logical array like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/985090/image.png)
I want to extrat the colum index of the cells where the first instance of 1 is detected. Like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/985095/image.png)
For example, you see here that the first two rows show 4, because that is where 1 is first detected.
0 Commenti
Risposta accettata
Walter Roberson
il 2 Mag 2022
C = sum(cumprod(~X, 2),1) + 1;
C will be one more than the number of columns for any row that has no 1.
4 Commenti
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Data Type Identification in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!