A compact way to remove empty rows in a cell array matrix ?
35 views (last 30 days)
Show older comments
A compact way to remove empty rows in a cell array matrix, as the following one?
>> a
a =
8×2 cell array
{'22-Jul-2021 17:00:00'} {[ 49]}
{0×0 double } {0×0 double}
{0×0 double } {0×0 double}
{0×0 double } {0×0 double}
{0×0 double } {0×0 double}
{'27-Jul-2021 20:00:00'} {[ 123]}
{'28-Jul-2021 06:00:00'} {[ 21]}
{'29-Jul-2021 13:00:00'} {[ 66]}
I tried this solution, but is there any more compact way ?
i = cellfun(@isempty,a);
a( any(i,2), : ) = []
a =
4×2 cell array
{'22-Jul-2021 17:00:00'} {[ 49]}
{'27-Jul-2021 20:00:00'} {[123]}
{'28-Jul-2021 06:00:00'} {[ 21]}
{'29-Jul-2021 13:00:00'} {[ 66]}
Accepted Answer
Matt J
on 11 Aug 2022
a = {
'22-Jul-2021 17:00:00', 49
'', []
'', []
'', []
'', []
'27-Jul-2021 20:00:00', 123
'28-Jul-2021 06:00:00', 21
'29-Jul-2021 13:00:00', 66 }
a= table2cell(rmmissing(cell2table(a)))
3 Comments
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!