Using the unique function to eliminate rows containing the same integers in a different order.
Show older comments
Hi,
I have an N x 2 array containing integers as shown below.
D = [1 4; 1 5; 2 3; 2 4; 2 5; 3 2; 4 1; 4 2; 4 5; 5 1; 5 2; 5 4]
I wish to remove rows that repeat numbers such as D(1,:) = [1 4] and D(:,7) = [4 1]. In this case, I would want to remove D(:,7) from the array as row 1 already contains numbers 1 and 4.
I typically use the unique function to both sort and filter my data in cases like this, however due to the different indices I have not yet managed to get this method to work.
[members]=unique(D,'rows');
Note: My desired output matrix is as follows:
D = [1 4; 1 5; 2 3; 2 4; 2 5; 3 2]
Any guidance would be very much appreciated!
Sam
1 Comment
James Tursa
on 5 Oct 2017
Edited: James Tursa
on 5 Oct 2017
Assuming that last [3 2] row is a typo should be [4 5] in your example.
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!