delete the rows will all zeros in multi-dimensional matrix
    3 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Dear all,
Let say I have a matrix M of size 6 x 3 x 3. And on each channel there are some zero rows (note that zero rows are evenly present in all channels). How can I remove the rows with all zeros.
For example,
M(:,:,1) =
     422   397   553
       0     0     0
       0     0     0
     476   494   520
       0     0     0
       0     0     0
M(:,:,2) =
       0     0     0
     384   494   504
       0     0     0
       0     0     0
     385   446   474
       0     0     0
M(:,:,3) =
             0           0           0
             0           0           0
          1194        1176        1295
             0           0           0
             0           0           0
          1202        1141        1295
3 件のコメント
  Azzi Abdelmalek
      
      
 2012 年 9 月 16 日
				
      編集済み: Azzi Abdelmalek
      
      
 2012 年 9 月 16 日
  
			If you remove certain rows, your chanels will have different sizes, then you should use cell array. In this case they have the same size, but not in general
採用された回答
  Andrei Bobrov
      
      
 2012 年 9 月 16 日
        
      編集済み: Andrei Bobrov
      
      
 2012 年 9 月 16 日
  
      out = reshape(M(bsxfun(@times,any(M,2),ones(1,size(M,2)))>0),[],size(M,2),size(M,3));
or only for your example
reshape(M(M>0),[],size(M,2),size(M,3))
0 件のコメント
その他の回答 (1 件)
  Azzi Abdelmalek
      
      
 2012 年 9 月 16 日
        
      編集済み: Azzi Abdelmalek
      
      
 2012 年 9 月 16 日
  
            for k=1:size(M,3)
          A=M(:,:,k)
          A(find(sum(A,2)==0),:)=[]
          res{k} = num2cell(A)
      end
      res{:}
参考
カテゴリ
				Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
			
	製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




