MATLAB Answers

0

Cell array: select cells based on length

Asked by Riccardo Rossi on 15 Jan 2019
Latest activity Commented on by Riccardo Rossi on 15 Jan 2019
Accepted Answer by KSSV
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!

  0 Comments

Sign in to comment.

Products


Release

R2018b

1 Answer

Answer by KSSV
on 15 Jan 2019
Edited by KSSV
on 15 Jan 2019
 Accepted Answer

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

  1 Comment

Thank you very much!

Sign in to comment.