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

1 view (last 30 days)
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]}

Accepted Answer

Alex Mcaulley
Alex Mcaulley on 21 May 2019
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) = [];

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!