remove empty rows of a cell

9 ビュー (過去 30 日間)
Pilar Julieta Tagliero
Pilar Julieta Tagliero 2021 年 6 月 23 日
Hello
How could I remove the empty rows of a cell array? For example if I have,
K =
{0×0 double } {0×0 double}
{0×0 double } {0×0 double}
{[ 0 10]} {[ 0]}
{[ 0 10]} {[ 0]}
How do I remove the first two rows?
Thanks in advance!

採用された回答

Scott MacKenzie
Scott MacKenzie 2021 年 6 月 23 日
reshape(K(~cellfun('isempty',K)), [], size(K,2))
  1 件のコメント
Pilar Julieta Tagliero
Pilar Julieta Tagliero 2021 年 6 月 24 日
Thank you!!

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

その他の回答 (1 件)

Joseph Cheng
Joseph Cheng 2021 年 6 月 23 日
編集済み: Joseph Cheng 2021 年 6 月 23 日
you can use the function cellfun() in conjunction with isempty:
clear K
%generate dummy K
for Cind = 1:2
for Rind = 1:4
if Rind<3
K{Rind,Cind}=[];
else
K{Rind,Cind}=randi(10,1,2);
end
end
end
%use the function isempty for each cell in K
emptyK= cellfun(@isempty,K)
emptyKrow = sum(emptyK,2)>1 %check to see which row in K is empty >1 for fully empty row >= if atleast 1 empty is in there
K(emptyKrow,:)=[] %kill off empty rows
  1 件のコメント
Pilar Julieta Tagliero
Pilar Julieta Tagliero 2021 年 6 月 24 日
Thank you!!

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by