필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Let's say:
cell_A : 1x3 cell class
cell_A={matrix_1 matrix_2 matrix_3 }
cell_A={[5x3 double] [1x3 double] [6x3 double]}={[1 1 1;2 2 2;3 3 3;4 4 4;5 5 5] [11 11 11] [0 0 0;1 1 1;2 2 2;3 3 3;4 4 4;5 5 5]}
matrix_1 [1 1 1;2 2 2;3 3 3;4 4 4;5 5 5] %5-by-3 matrix
matrix_2 [11 11 11] %1-by-3 matrix
matrix_3 [0 0 0;1 1 1;2 2 2;3 3 3;4 4 4;5 5 5] %6-by-3 matrix
If I wanna count how many row of each matrix in cell A, the result is:
ans=[ 5; 1 ;6];
Now, I wanna delete matrix of cell A, If the number row in matrix <2. How can I do that? The result is:
result : 1x2 cell class
result={matrix_1 ; matrix_3 }
result={[5x3 double] [6x3 double]}={[1 1 1;2 2 2;3 3 3;4 4 4;5 5 5] [0 0 0;1 1 1;2 2 2;3 3 3;4 4 4;5 5 5]}

채택된 답변

Alex Mcaulley
Alex Mcaulley 2019년 5월 21일
cell_A = {[1 1 1;2 2 2;3 3 3;4 4 4;5 5 5];[11 11 11];[0 0 0;1 1 1;2 2 2;3 3 3;4 4 4;5 5 5]};
cell_A(cellfun(@size,cell_A,repmat({1},size(cell_A))) < 2) = [];
  댓글 수: 2
Stephen23
Stephen23 2019년 5월 21일
편집: Stephen23 2019년 5월 21일
Using cellfun's backwards-compatibility syntax makes this simpler (two lines for clarity):
idx = cellfun('size',A,1)<2;
A(idx) = []

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by