MATLAB: Eliminating Duplicate Rows in an Array based on a condition

MATLAB

I have an 1000 by 7 array. The first six columns are duplicates across some sets of rows.
If the first six columns are duplicated in another row, I want to eliminate some of the duplicates based on a condition in the 7th column.
How can I do this?

Best Answer

The simplest way to do this is to use "sortrows" so that duplicates are next to each other.
The code snippet below illustrates how to do this for an array 'A'. Note that here, a row is removed if it is a duplicate, and if the 7th entry of the row equals 'dup'.
[B, idx] = sortrows(A,(1:6));
toRmv = [];
for ii = 1:size(A,1)
if A(ii,7) == dup
toRmv(end+1) = idx(ii);
end
end
A(toRmv,:) = [];