How can I delete a row from a cell aray, with empty cell as first column

2 ビュー (過去 30 日間)
Dimitris Kokkinos
Dimitris Kokkinos 2014 年 3 月 25 日
コメント済み: Arnab Roy 2020 年 12 月 1 日
I have a cell aray with 2 columns.
A={[7;8],6;[],19;[3;4;5;6],11;[],25;[4;5],58;[],63}
I want to delete all rows which contain empty cells.How can I do that?

採用された回答

Ken Atwell
Ken Atwell 2014 年 3 月 25 日
編集済み: Ken Atwell 2014 年 3 月 25 日
I think this is what you are after: The line of code below will call isempty on each row in the first column, and then trim A to only those rows that are not empty.
>> A(~cellfun(@isempty, A(:,1)), :)
ans =
[2x1 double] [ 6]
[4x1 double] [11]
[2x1 double] [58]
  2 件のコメント
Dimitris Kokkinos
Dimitris Kokkinos 2014 年 3 月 25 日
It was exactly what I was looking for.So simple,but so difficult to find. Thank you Ken.
Arnab Roy
Arnab Roy 2020 年 12 月 1 日
Very elegant solution, thank you Ken!

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

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2014 年 3 月 25 日
A(~any(cellfun(@isempty, A),2), :)
  2 件のコメント
Dimitris Kokkinos
Dimitris Kokkinos 2014 年 3 月 25 日
Nice option.Thank you,too, Andrei.
Mucahit Kavakli
Mucahit Kavakli 2020 年 11 月 3 日
Thanks

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

カテゴリ

Help Center および File ExchangeFunctions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by