Remove row in cell array depending on value of first column.
7 views (last 30 days)
Show older comments
I would like to know how to remove each row on each cell in a cell array where the value of the first column is below 6.
I’ve got this cell array with hundreds of cells where each cell is a matrix of a different dimension. The fist 8 cells look like:
C = {36x4 double}
{5x18 double}
{5x2 double}
{13x9 double}
{2x7 double}
{20x2 double}
{20x2 double}
{9x7 double}
For example the third cell of C is {5x2 double} and is composed of:
1 5
19 10
5 4
6 6
21 9
So the end result for that cell should be:
19 10
6 6
21 9
0 Comments
Accepted Answer
More Answers (2)
Cedric
on 22 Aug 2015
Edited: Cedric
on 22 Aug 2015
The easiest way is using a loop:
for cId = 1 : numel( C )
isLt6 = C{cId}(:,1) < 6 ;
C{cId} = C{cId}(~isLt6,:) ; % Or C{cId}(isLt6,:) = [] ;
end
Then you have more compact ways to do it, which may not be more efficient overall, e.g.:
C = cellfun( @(c) c(c(:,1)>=6,:), C, 'UniformOutput', false ) ;
0 Comments
the cyclist
on 22 Aug 2015
Edited: the cyclist
on 22 Aug 2015
output = cellfun(@(x)x(x(:,1) >= 6,:),C,'UniformOutput',false)
0 Comments
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!