Count number of cells separating two trues in logical vector
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Enrico Gambini
      
 el 12 de Oct. de 2022
  
    
    
    
    
    Comentada: Enrico Gambini
      
 el 12 de Oct. de 2022
            Hello!
I would like to find a fast procedure to count the number of cells separating two trues in a logical vector, and store the results in a new numeric vector. 
For instance:
x=[true;false;false;false;true;false;false;true;false;true];
The output should be
output=[4;3;2]; % Hence, it counts also the "first" true
Hope the question is clear.
Thank you!
0 comentarios
Respuesta aceptada
  Matt J
      
      
 el 12 de Oct. de 2022
        x=[true;false;false;false;true;false;false;true;false;true];
diff(find(x))
Más respuestas (0)
Ver también
Categorías
				Más información sobre Matrix Indexing en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!