Delete empty cell array
13 ビュー (過去 30 日間)
古いコメントを表示
Hi all,I have a problem regarding deletion in cell array.
The cell array is like A=
neigh node_id
[] [1]
[3X1] [2]
[5X1] [3]
[2X1] [4]
[] [5]
[9X1] [6]
Now, i want to delete the cells A{1,:} and A{5,:},as (A{1,1}=[] and A{5,1}=[]). Thus resulting array would be like:
A=
neigh node_id
[3X1] [2]
[5X1] [3]
[2X1] [4]
[9X1] [6]
the code
A = A(~cellfun('isempty', A)); is not able to work on this type of array A=cell(6,2).
Thanks
1 件のコメント
Jan
2015 年 8 月 3 日
"is not able to work" is a bad description of the problem. Please post the error message or explain in detail the difference between the results and your expectations.
採用された回答
Jan
2015 年 8 月 3 日
A = A(~any(cellfun('isempty', A), 2), :);
3 件のコメント
Marcio Teixeira
2021 年 4 月 27 日
That is clean and elegant solution Jan. I learn a lot with this community.
Thank you very much.
その他の回答 (1 件)
Manolis Michailidis
2015 年 8 月 3 日
編集済み: Manolis Michailidis
2015 年 8 月 3 日
have you tried something like this?
for i=1:length(your_cell_size)
idx(i) = find(~cellfun(@isempty,A{i}));
end
A=A{~idx}
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!