sort a cell array based on the number of rows in each cell

1 回表示 (過去 30 日間)
merialu
merialu 2018 年 11 月 9 日
コメント済み: merialu 2018 年 11 月 12 日
Hi, I have an cell array of 6031x1 cell. each cell contain as matrix of different number of rows but with 53 columns.
i want to remove all cells with 1 or 2 rows.
i have tried to use this code to sort the cells and than delete them in a second step:
NrowsB = cellfun('size',mycellarray,1) ;
[~, ri] = sort(NrowsB);
but this does not work. Any ideas how to sort the cells or how to delete the cells directly?

採用された回答

Stephen23
Stephen23 2018 年 11 月 9 日
編集済み: Stephen23 2018 年 11 月 9 日
Your question is confused: you ask that you want to "sort a cell array based on the number of rows in each cell", but then later you state that you "want to remove all cells with 1 or 2 rows."
So which do you want to do: sort or delete the cell array?
Here is how you can delete those cells:
NrowsB = cellfun('size',mycellarray,1) ;
mycellarray(NrowsB<3) = []
Here is how you can sort those cells:
[~,idx] = sort(NrowsB);
mycellarray = mycellarray(idx);
  1 件のコメント
merialu
merialu 2018 年 11 月 12 日
Yes, sorry for the confusion. Your answer is perfect though, now i know how to sort and delete. thank you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by