how to remove empty cell array contents?
古いコメントを表示
Hello, I've got a cell array, lets say:
R =
[ 691x2 double]
[]
[]
[]
[]
[ 12x2 double]
[ 11x2 double]
[]
[]
[ 112x2 double]
[ 13x2 double]
Does anyone know of a quick way I could remove the non-zero elements of the cell array? This cell array will be a different length and will have a different number of non-zero elements each time, dependent on another loop
Thanks, Jim
採用された回答
その他の回答 (1 件)
David Young
2012 年 1 月 25 日
Rnew = R(~cellfun(@isempty, R))
3 件のコメント
Harold
2012 年 4 月 25 日
I'm also trying to remove empty cells from a matrix but I can't figure out how to maintain the order for each row and column.
D=
{[-24.7697910000000,-15.8191235000000],[],[-12.6771670000000,20.4587480000000],[];[],[-20.6771670000000,-3.54125200000000],[-11.9803417500000,-14.5401785500000],[];[],[-20.6771670000000,-3.54125200000000],[4.32283300000000,-1.04125200000000],[];[],[13.0196582500000,-12.0401785500000],[],[-24.7697910000000,-15.8191235000000];[-11.9803417500000,-14.5401785500000],[],[4.32283300000000,-1.04125200000000],[];[],[-12.6771670000000,20.4587480000000],[],[13.0196582500000,-12.0401785500000]}:
I need
[-24.7697910000000,-15.8191235000000] [-12.6771670000000,20.4587480000000]
[-20.6771670000000,-3.54125200000000] [-11.9803417500000,-14.5401785500000]
[-20.6771670000000,-3.54125200000000] [4.32283300000000,-1.04125200000000]
[13.0196582500000,-12.0401785500000] [-24.7697910000000,-15.8191235000000]
[-11.9803417500000,-14.5401785500000] [4.32283300000000,-1.04125200000000]
[-12.6771670000000,20.4587480000000] [13.0196582500000,-12.0401785500000]
Andrei Bobrov
2012 年 4 月 25 日
D1 = D.';
out = reshape(D1(~cellfun(@isempty,D1)),2,[])';
Daniel Bridges
2017 年 3 月 1 日
>> data(~structfun(@isempty,data))
Error using structfun
Inputs to STRUCTFUN must be scalar structures.
カテゴリ
ヘルプ センター および File Exchange で Operators and Elementary Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
