Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Removal of repeated rows with the same elements

Subject: Removal of repeated rows with the same elements

From: aiden

Date: 10 Oct, 2010 22:06:03

Message: 1 of 3

Dear friends,

 I have a matrix as:
 
b = [ 3 4
        6 7
        4 3
        5 4]

I wish to remove a row's identical elements, i.e. both the same elements.
So in 'b' I wish to remove the third row since it is already repeated above , so my final answer should be:

new_b = [ 3 4;
                6 7;
                5 4]

How can i do this?

Subject: Removal of repeated rows with the same elements

From: dpb

Date: 10 Oct, 2010 22:43:24

Message: 2 of 3

aiden wrote:
> Dear friends,
>
> I have a matrix as:
> b = [ 3 4
> 6 7
> 4 3
> 5 4]
>
> I wish to remove a row's identical elements, i.e. both the same elements.
> So in 'b' I wish to remove the third row since it is already repeated
> above , so my final answer should be:
>
> new_b = [ 3 4;
> 6 7;
> 5 4]
>
> How can i do this?

unique(sort(b,2),'rows')

--

Subject: Removal of repeated rows with the same elements

From: Roger Stafford

Date: 11 Oct, 2010 00:56:04

Message: 3 of 3

"aiden " <aidenjobe@gmail.com> wrote in message <i8tdcb$d9j$1@fred.mathworks.com>...
> Dear friends,
>
> I have a matrix as:
>
> b = [ 3 4
> 6 7
> 4 3
> 5 4]
>
> I wish to remove a row's identical elements, i.e. both the same elements.
> So in 'b' I wish to remove the third row since it is already repeated above , so my final answer should be:
>
> new_b = [ 3 4;
> 6 7;
> 5 4]
>
> How can i do this?
- - - - - - - - - -
  If you wish to preserve the original order, do this:

 [ig,m] = unique(sort(b,2),'rows','first');
 new_b = b(sort(m),:);

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us