How to check if a 3d matrix has any 2D submatrix with non zero elements?
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    pietro
      
 el 30 de Mayo de 2014
  
    
    
    
    
    Comentada: pietro
      
 el 30 de Mayo de 2014
            Hi all,
I have a 3D matrixnd I need to check if it has any sub 2D matrix with non zero elements.
a(:,:,1) =
       0     0
       0     0
a(:,:,2) =
       1     0
       0     0
the results should be
[0 1].
Thanks
cheers
0 comentarios
Respuesta aceptada
  Sean de Wolski
      
      
 el 30 de Mayo de 2014
        pagesWithNonZeros = squeeze(any(any(x,1),2))
You can pass dim into any to test if there are any nonzero elements in that dimension.
0 comentarios
Más respuestas (1)
  Hugo
      
 el 30 de Mayo de 2014
        You can just do
 [any(any(a(:,:,1)>0)),any(any(a(:,:,2)>0))]
or just shorter
 nonzero2D=@(a,k)any(any(a(:,:,k)>0))
 [nonzero2D(a,1), nonzero2D(a,2)]
Is that what you want?
Ver también
Categorías
				Más información sobre Creating and Concatenating Matrices 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!


