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

1 回表示 (過去 30 日間)
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]}

採用された回答

Alex Mcaulley
Alex Mcaulley 2019 年 5 月 21 日
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) = [];
  2 件のコメント
Stephen23
Stephen23 2019 年 5 月 21 日
編集済み: Stephen23 2019 年 5 月 21 日
Using cellfun's backwards-compatibility syntax makes this simpler (two lines for clarity):
idx = cellfun('size',A,1)<2;
A(idx) = []
Alex Mcaulley
Alex Mcaulley 2019 年 5 月 21 日
Thanks Stephen. I had never seen the backwards-compatibility before.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by