I have a cell array as seen in the image. I want to delete the rows of the cell array where the first column is less than 3. Thanks.

 採用された回答

Walter Roberson
Walter Roberson 2016 年 10 月 7 日

1 投票

mask = cell2mat(YourCell(:,1)) < 3;
YourCell(mask, :) = [];

1 件のコメント

Tyler Smith
Tyler Smith 2016 年 10 月 7 日
Works great! Thanks.

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

その他の回答 (2 件)

Hedayat
Hedayat 2019 年 11 月 28 日

1 投票

If you want to delete more than one rows of cell you can ...
a= cell(5,5)
a =
5×5 cell array
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
a([2,3],:)=[]
a =
3×5 cell array
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2016 年 10 月 7 日

0 投票

a is the cell array
b=find(cellfun(@(x) size(x,1)<3,a)==1);
while ~isempty(b)
a(b(1))=[];
b=b-1;
b(1)=[];
end

1 件のコメント

Walter Roberson
Walter Roberson 2016 年 10 月 7 日
No, this checks for vectors less than 3 elements anywhere in the cell array.
The == 1 is redundant because the places that satisfy <3 will already return 1 and the other places will return 0 and find() automatically checks for non-zero. The code there is sort of like
find((x < 3) == true)
when you could just use
find(x < 3)

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

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

質問済み:

2016 年 10 月 7 日

回答済み:

2019 年 11 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by