How to find the number of continuous data set along each row in the matrix given below? Desired result given below.
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Payel
 el 1 de Jul. de 2023
  
    
    
    
    
    Comentada: John D'Errico
      
      
 el 1 de Jul. de 2023
            V =[0 0 1 1 1 0 1 1;1 1 0 0 0 0 1 1;0 0 1 1 1 0 0 0;1 1 1 0 0 1 1 1;0 1 1 1 0 0 1 1;0 1 1 0 0 1 1 0;0 1 1 1 1 1 1 0]
desired_result=[2;2;1;2;2;2;1]
3 comentarios
  John D'Errico
      
      
 el 1 de Jul. de 2023
				Exactly what is different in this question from the one where you got two answers already?
Respuesta aceptada
  Animesh
      
 el 1 de Jul. de 2023
        Hey @Payel
You can try something like this : 
V = [0 0 0 0 0 0 0 0;
     1 1 0 0 0 0 1 1;
     0 0 1 1 1 0 0 0;
     1 1 1 0 0 1 1 1;
     0 1 1 1 0 0 1 1;
     0 1 1 1 1 1 1 0;
     0 1 1 1 1 1 1 0];
desired_result = zeros(size(V, 1), 1);
for i = 1:size(V, 1)
    counter = 0;
    for j = 1:size(V, 2)
        if (V(i, j) ~= 0) && (j == 1 || V(i, j - 1) == 0)
            counter = counter + 1;
        end
    end
    desired_result(i) = counter;
end
desired_result
0 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
			
	Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!