omit nonzero elemnt in cell

조회 수: 3 (최근 30일)
NA
NA 2019년 6월 28일
답변: Andrei Bobrov 2019년 6월 28일
A={[3,4],[8,9],[1,2],0,0,0};
A(cell2mat(A)==0)={[]};
I used this code, but have error
Error using cat
Dimensions of arrays being concatenated are not consistent.
Error in cell2mat (line 2)
m{n} = cat(2,c{n,:});
Result should be
A={[3,4],[8,9],[1,2],[],[],[]};

채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 6월 28일
A(cellfun(@(x)numel(x) == 1 && x == 0,A)) = {[]};

추가 답변 (1개)

Himanshu tripathi
Himanshu tripathi 2019년 6월 28일

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by