Cell array: select cells based on length

조회 수: 3 (최근 30일)
Riccardo Rossi
Riccardo Rossi 2019년 1월 15일
댓글: Riccardo Rossi 2019년 1월 15일
Hi everyone,
If i have a cell array like this:
{1×3 double} {1×3 double} {2×3 double} {1×3 double} {4×3 double}
how can i extract only the 1x3 double cells (of which I do not know the exact location into cell array)?
Thank's a lot!

채택된 답변

KSSV
KSSV 2019년 1월 15일
편집: KSSV 2019년 1월 15일
C = cell(5,1) ;
C{1} = rand(1,3) ;
C{2} = rand(1,3) ;
C{3} = rand(4,3) ;
C{4} = rand(1,3) ;
C{5} = rand(4,3) ;
row = cellfun(@(x) size(x,1),C);
iwant = C(row>1)
Or you can use a loop:
C = cell(5,1) ;
C{1} = rand(1,3) ;
C{2} = rand(1,3) ;
C{3} = rand(4,3) ;
C{4} = rand(1,3) ;
C{5} = rand(4,3) ;
for i = 1:length(C)
if size(C{i},1)>1
C{i}
end
end

추가 답변 (0개)

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by