Remove row in cell array depending on value of first column.
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (2)
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 ) ;
the cyclist
le 22 Août 2015
Modifié(e) : the cyclist
le 22 Août 2015
output = cellfun(@(x)x(x(:,1) >= 6,:),C,'UniformOutput',false)
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!