removing duplicates in an array
60 次查看(过去 30 天)
显示 更早的评论
If i have the following array
a =[1,1,1,2,2,1,1,6,6,6,8,8,2,2,3,3,2,2]
When i do unique(a,'stable'), i get
[1,2,6,8,3]
I want the following result
[1,2,1,6,8,2,3,2]
0 个评论
采纳的回答
更多回答(1 个)
Brent F
2021-6-10
编辑:Brent F
2021-6-10
- Package as a function
- Handle case where column-vector is given (return in same format as given)
function [uniqueSequence] = DedupSequence (seq)
% Eliminate sequentially repeated rows
% Create row vector for diff (must transpose if given a column vector)
if size(seq,1) > 1
seqCopy = seq(:,1)';
else
seqCopy = seq;
end
uniqueSequence = seq([true, diff(seqCopy)~=0]);
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!