フィルターのクリア

getting rid of empty cells in a cell array

39 ビュー (過去 30 日間)
Sebastiano delre
Sebastiano delre 2014 年 1 月 15 日
コメント済み: Nisha Bharti 2021 年 10 月 10 日
Hi,
can you please help me with this? I have the following cell array
x = {1,[],'ciao',[],[]};
I want to exclude the empty cells, and get another array like this:
y = {1,'ciao'};
Thank you!

採用された回答

Niklas Nylén
Niklas Nylén 2014 年 1 月 15 日
First, check which cells that are empty using the function isempty. Since isempty does not accept cell arrays as input, you can use the cellfun function. This will call a function with each element of a cell array:
index = cellfun(@isempty, x) == 0;
y = x(index)
  1 件のコメント
Sebastiano delre
Sebastiano delre 2014 年 1 月 15 日
thank you!

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

その他の回答 (1 件)

Mischa Kim
Mischa Kim 2014 年 1 月 15 日
編集済み: Mischa Kim 2014 年 1 月 15 日
Try y=x(~cellfun('isempty',x))
  4 件のコメント
Yiqian Qian
Yiqian Qian 2021 年 5 月 27 日
I have the same question above, how to apply this to a specific row or colums.
Nisha Bharti
Nisha Bharti 2021 年 10 月 10 日
Yes, same query

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by