Finding consecutive zeros in an array. Not able to solve using diff command
Mostrar comentarios más antiguos
I have an array like below
a=[0 0 1 1 -1 0 0 0 1 1 1 -1 0 0 1 -1] %in my actual code, there are many elements
There is a -1 after every set of 1s like an end marker. I want to find the largest number of consecutive zeros present. Here it would be 3.
I used diff(a) but in this case even 1-1=0 along with 0-0=0. I also tried manipulating the array with some math operations and then using diff(a) but no use.
Any idea on how to do this?
Respuesta aceptada
Más respuestas (1)
Using,
[~,~,runLengths]=groupLims(groupTrue(~a),1);
maxLength=max(runLengths)
1 comentario
Jaya
el 24 de Oct. de 2021
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!