Delete double cell array entries
3 次查看(过去 30 天)
显示 更早的评论
How can I delete double entries in a cell array? I don't want to use a loop. For example I have:
CellArray={[1 2 3] [1 2] [3 5 6 7] [1 2] [2 4] }
And as a result I want to get this:
NewCellArray={[1 2 3] [1 2] [3 5 6 7] [2 4] }
Thank you very much and have a nice day!
0 个评论
采纳的回答
Azzi Abdelmalek
2013-3-20
编辑:Azzi Abdelmalek
2013-3-20
CellArray={[1 2 3] [1 2] [3 5 6 7] [1 2] [2 4] };
m=max(cellfun(@numel,CellArray));
v=cellfun(@(x) [x inf(1,m-numel(x))],CellArray,'un',0);
[~,ii]=unique(cell2mat(v'),'rows');
CellArray=CellArray(ii)
更多回答(2 个)
Friedrich
2013-3-20
Hi,
one line:
NewCellArray = cellfun(@str2num, unique(cellfun(@num2str, CellArray,'UniformOutput',false)),'UniformOutput',false)
Babak
2013-3-20
CellArray={[1 2 3] [1 2] [3 5 6 7] [1 2] [2 4] };
NewCellArray = [CellArray(1:3) CellArray(5)];
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!