How to delete rows of empty cells from a cell array
19 次查看(过去 30 天)
显示 更早的评论
Is there a way I can delete empty cell arrays and preserve the order of the cell?
In the code I provided, it would be very easy to hardcode, but is there a way of doing it where you don't know where the 1st and last empty value is? The code I provided is just a simplified version of what I am trying to do.
% Create cell array
A = cell{4,3};
% Fill first 2 rows of cell
for k = 1:2
A{k,1} = 1;
A{k,2} = 2;
A{k,3} = 3;
A{k,4} = 4;
end
% Delete the 2 empty rows
% Desired output
%{
A =
2×4 cell array
{[ 1]} {[ 2]} {[ 3]} {[ 4]}
{[ 1]} {[ 2]} {[ 3]} {[ 4]}
%}
0 个评论
采纳的回答
Walter Roberson
2021-2-24
A = cell(4,3);
% Fill first 2 rows of cell
for k = 1:2
A{k,1} = 1;
A{k,2} = 2;
A{k,3} = 3;
A{k,4} = 4;
end
A(all(cellfun(@isempty, A),2),:) = []
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!