필터 지우기
필터 지우기

remove cell array content with condition: length of element in cell smaller than specific value

조회 수: 5 (최근 30일)
Let's say:
A : 3x1 cell class
A={cell_1 ; cell_2 ; cell_3 }
A={[1x2 double];[1x5 double];[1x3 double]}
cell_1 [999,222]
cell_2 [444,123,2000,789,1000]
cell_3 [5000,9000,4000]
If I wanna count how many element in each cell:
out1= cellfun('length',A);
out1=[2;5;3]
Now, I wanna delete the row of cell A, If the number element in that row <3. How can I do that? The result is:
result : 2x1 cell class
result={cell_2 ; cell_3 }
result={[1x5 double];[1x3 double]}
cell_2 [444,123,2000,789,1000]
cell_3 [5000,9000,4000]

채택된 답변

Stephen23
Stephen23 2018년 3월 4일
편집: Stephen23 2018년 3월 4일
A(cellfun('length',A)<3) = []
or if you want to leave the original variable unchanged:
B = A(cellfun('length',A)>=3);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by