How to remove zeros from a 3D array

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

KSSV
KSSV 2017년 3월 30일
If you remove the zeros.....the dimensions of the matrix changes...Is that okay?
Geoff Hayes
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?
Burak
Burak 2017년 3월 30일
편집: Burak 2017년 3월 30일
@KSSV yes, dimensions change and it is ok, I need to get inverse of A for all m but there are zeros and it can't be inversed.
@Geoff I need to remove all rows for A(1,:,k), A(2,:,k) ,...,A(n,:,N) etc.
By the way, thank you both for your interest.

댓글을 달려면 로그인하십시오.

답변 (1개)

Guillaume
Guillaume 2017년 3월 30일

0 개 추천

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.

댓글 수: 2

Burak
Burak 2017년 3월 30일
I will try this, thank you for your interest.
Burak
Burak 2017년 3월 30일
it didn't work , because A's size change when we remove zeros.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2017년 3월 30일

댓글:

2017년 3월 30일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by