How to remove duplicate rows from matrix

 I want to remove duplicate rows from a matrix. I read How can I remove duplicates in an array but keep the same order?, but this is not exactly what I want.

The solution above removes duplicate values (cells) from matrix (and returns a vector), but I need to remove duplicate rows and return a matrix — the same matrix without duplicate rows.

Example:  

a = [1,2; 3,4; 5,6; 1,2; 7,8]

a =
     1     2
     3     4
     5     6
     1     2
     7     8

%...

ans =
     1     2
     3     4
     5     6
     7     8 
The order doesn't matter.  

NOTE:-


Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.   

Answers: 

See http://www.mathworks.com/help/techdoc/ref/unique.html

b = unique(A, 'rows') returns the unique rows of A. 

Here is my solution 

 

package com.test;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class DuplicateInMatrix {
    public static void main(String[] args) {
        Integer[][] arr = { { 1, 2, 3 }, { 4, 5, 6 }, { 1, 2, 3 } };
        Set set = new HashSet<>();
        for (int i = 0; i < arr.length; i++) {
            set.add(new Element(arr.length, arr[i]));
        }

        buildResultArray(set);
 

Comments

Popular posts from this blog

Why do I get a "Too many input arguments" error when not passing any?

Why Red, Green, Blue channels of image separetely are grayscaled (Matlab)?

How is full convolution performed using MATLAB's conv2 function?