问题
Using this method on a 8x8 matrix:
>> [junk,index] = unique(data,'first'); %# Capture the index, ignore junk
>> data(sort(index)) %# Index data with the sorted index
Outputs the format in 64x1 format (if no repeats are found) or nx1 if some repeats are found.
My question is how do I keep the matrix format without the sorting?
i need it to check unique(rows) for duplicates not unique cells. And to delete the duplicate rows but keep the format (dont arrange/sort).
回答1:
If you want unique rows, while keeping original order, try this:
[M,ind] = unique(data, 'rows', 'first');
[~,ind] = sort(ind);
M = M(ind,:);
Example:
>> 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
来源:https://stackoverflow.com/questions/7781749/junk-index-and-unique-on-a-matrix-how-to-keep-matrix-format