G G*_* Gr 3 sorting matlab unique matrix duplicates
在8x8矩阵上使用此方法:
>> [junk,index] = unique(data,'first'); %# Capture the index, ignore junk
>> data(sort(index)) %# Index data with the sorted index
Run Code Online (Sandbox Code Playgroud)
以64x1格式输出格式(如果未找到重复)或如果找到重复,则输出nx1.
我的问题是如何在没有排序的情况下保留矩阵格式?
我需要它来检查重复的唯一(行)而不是唯一的单元格.并删除重复的行但保留格式(不要排列/排序).
如果您想要保持原始订单的唯一行,请尝试以下操作:
[M,ind] = unique(data, 'rows', 'first');
[~,ind] = sort(ind);
M = M(ind,:);
Run Code Online (Sandbox Code Playgroud)
例:
>> data = randi(2,[8 3]);
data =
1 2 1
1 2 1
1 1 2
2 2 2
1 1 1
2 2 2
2 2 2
2 1 1
>> M
M =
1 2 1
1 1 2
2 2 2
1 1 1
2 1 1
Run Code Online (Sandbox Code Playgroud)