Find the index of zero in cell and put it as empty
4 次查看(过去 30 天)
显示 更早的评论
A={[45;101],[2;7],[5;8],0,0};
A(cell2mat(A)==0)={[]}; % I want to find zero and put in empty
A should be
A={[45;101],[2;7],[5;8],[],[]};
0 个评论
采纳的回答
Guillaume
2020-1-7
编辑:Guillaume
2020-1-7
A(cellfun(@(x) isequal(x, 0), A)) = {[]}; %replace any cell whose content is the scalar 0 by empty
is one way.
edit: fixed code.
6 个评论
Guillaume
2020-1-7
Do'h! I knew this was simple. Thanks, Stephen. For some reason, I had it in my head that {} and {[]} were the same thing.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!