How to remove zeros from a 3D array
1 次查看(过去 30 天)
显示 更早的评论
Hi everyone, I have a 3D array like this A(v,n,m) , I need to remove zero columns and and rows from first 2 dimens
for m=1:N
A(~any(A,2),:,m)=[];
A(:,~any(A,1),:m)=[];
end
I tried this code but I got error. If anyone can help me, appreciated.
3 个评论
Geoff Hayes
2017-3-30
Burak - are you trying to remove all columns or rows that are all zeros or at least one zero in that row or column? If there is a row to be removed at A(1,:,1) do you remove this row from A(1,:,k) for all k?
回答(1 个)
Guillaume
2017-3-30
Well, you cannot remove a row of column from one page but not the other pages, so the loop does not make much sense.
You could do this:
A(any(~any(A, 2), 3)) = []; %remove row from all pages when one row in any of the pages has a 0
A(any(~any(A, 1), 3)) = []; %remove column from all pages when one column in any of the pages has a 0
if that is appropriate for you.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!