getting rid of empty cells in a cell array
20 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
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 件)
Mischa Kim
2014 年 1 月 15 日
編集済み: Mischa Kim
2014 年 1 月 15 日
Try y=x(~cellfun('isempty',x))
4 件のコメント
Yiqian Qian
2021 年 5 月 27 日
I have the same question above, how to apply this to a specific row or colums.
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!