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:
I want answer

Subject: I want answer

From: khalil

Date: 19 Apr, 2012 02:40:25

Message: 1 of 7

How I can remove rows from matrix each elemnts in these rows are equals
Ex:
m=[1 2 3;1 1 1;4 5 8;4 5 8;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;4 5 8;7 8 5; 47 9 5;7 8 5;5 322 5;7 8 55];

Subject: I want answer

From: Nasser M. Abbasi

Date: 19 Apr, 2012 03:03:57

Message: 2 of 7

On 4/18/2012 9:40 PM, khalil wrote:
> How I can remove rows from matrix each elemnts in these rows are equals
> Ex:
> m=[1 2 3;1 1 1;4 5 8;4 5 8;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;4 5 8;7 8 5; 47 9 5;7 8 5;5 322 5;7 8 55];

m =

      1 2 3
      1 1 1
      4 5 8
      4 5 8
      1 1 1
      1 1 1
      1 1 1
      1 1 1
      1 1 1
      1 1 1
      1 1 1
      1 1 1
      4 5 8
      7 8 5
     47 9 5
      7 8 5
      5 322 5
      7 8 55

-----------------------
r=cell2mat(arrayfun(@(i) length(unique(m(i,:))),1:length(m),'UniformOutput',false));
m(r~=1,:)
--------------------------

      1 2 3
      4 5 8
      4 5 8
      4 5 8
      7 8 5
     47 9 5
      7 8 5
      5 322 5
      7 8 55


--Nasser

Subject: I want answer

From: matt dash

Date: 19 Apr, 2012 03:05:31

Message: 3 of 7

"khalil " <kh_ali_khalil@yahoo.com> wrote in message <jmntup$hqc$1@newscl01ah.mathworks.com>...
> How I can remove rows from matrix each elemnts in these rows are equals
> Ex:
> m=[1 2 3;1 1 1;4 5 8;4 5 8;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;4 5 8;7 8 5; 47 9 5;7 8 5;5 322 5;7 8 55];

n=m(~all(bsxfun(@eq,m,m(:,1)),2),:)

Subject: I want answer

From: dpb

Date: 19 Apr, 2012 03:55:10

Message: 4 of 7

On 4/18/2012 9:40 PM, khalil wrote:
> How I can remove rows from matrix each elemnts in these rows are equals
> Ex:
> m=[1 2 3;1 1 1;4 5 8;4 5 8;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1
> 1;4 5 8;7 8 5; 47 9 5;7 8 5;5 322 5;7 8 55];

Not sure which solution you're interested in...

 >> unique(m,'rows')
ans =
      1 1 1
      1 2 3
      4 5 8
      5 322 5
      7 8 5
      7 8 55
     47 9 5
 >>

--

Subject: I want answer

From: Nasser M. Abbasi

Date: 19 Apr, 2012 04:23:34

Message: 5 of 7

On 4/18/2012 10:55 PM, dpb wrote:
> On 4/18/2012 9:40 PM, khalil wrote:
>> How I can remove rows from matrix each elemnts in these rows are equals
>> Ex:
>> m=[1 2 3;1 1 1;4 5 8;4 5 8;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1
>> 1;4 5 8;7 8 5; 47 9 5;7 8 5;5 322 5;7 8 55];
>
> Not sure which solution you're interested in...
>
> >> unique(m,'rows')
> ans =
> 1 1 1
> 1 2 3
> 4 5 8
> 5 322 5
> 7 8 5
> 7 8 55
> 47 9 5
> >>
>
> --
>

No, the above does not work.

OP wanted rows which do NOT have same elements in them.

In the above, your first row is [1 1 1], so it does NOT
belong in the answer.

--Nasser

Subject: I want answer

From: Roger Stafford

Date: 19 Apr, 2012 05:49:07

Message: 6 of 7

"khalil " <kh_ali_khalil@yahoo.com> wrote in message <jmntup$hqc$1@newscl01ah.mathworks.com>...
> How I can remove rows from matrix each elemnts in these rows are equals
> Ex:
> m=[1 2 3;1 1 1;4 5 8;4 5 8;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;4 5 8;7 8 5; 47 9 5;7 8 5;5 322 5;7 8 55];
- - - - - - - - - - -
 m(all(diff(m,1,2)==0,2),:) = [];

Roger Stafford

Subject: I want answer

From: dpb

Date: 19 Apr, 2012 13:15:04

Message: 7 of 7

On 4/18/2012 11:23 PM, Nasser M. Abbasi wrote:
> On 4/18/2012 10:55 PM, dpb wrote:
>> On 4/18/2012 9:40 PM, khalil wrote:
>>> How I can remove rows from matrix each elemnts in these rows are equals
>>> Ex:
....

>
> OP wanted rows which do NOT have same elements in them.
>
> In the above, your first row is [1 1 1], so it does NOT
> belong in the answer.

Your parsing of his request is probably better than mine...I couldn't
decide just what he really did want so threw it in as a choice (as
noted) just in case....

--

Tags for 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