remove rows with repeat numbers

  • Follow


Hi
how can i remove the rows with repeated digits in A in order to form new_A?

A =  
     72     81
     51     67
     33     33
     25     24
     50     50
     
        
new_A = 

                      72     81
                      51     67
                      25     24
  
thanks            
0
Reply Kurt 10/18/2010 4:32:03 AM

On 10/17/2010 9:32 PM, Kurt wrote:
> Hi
> how can i remove the rows with repeated digits in A in order to form new_A?
>
> A =
>       72     81
>       51     67
>       33     33
>       25     24
>       50     50
>
>
> new_A =
>
>                        72     81
>                        51     67
>                        25     24
>
> thanks

one way:

A =  [72     81;
      51     67;
      33     33;
      25     24;
      50     50]


A(find(arrayfun(@(i)length(unique(A(i,:))),1:size(A,1))==size(A,2)),:)

ans =
     72    81
     51    67
     25    24


--Nasser
0
Reply Nasser 10/18/2010 5:10:49 AM


thanks nasser,

I have another issue. With the code below : 

Please note that the function 'npermutek' can be found at:
http://www.mathworks.com/matlabcentral/fileexchange/11462-npermutek

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

A = [    1     4     7]
        
A = npermutek(A,2)
A= sort(A,2)
A =unique(A,'rows' )
A(find(arrayfun(@(i)length(unique(A(i,:))),1:size(A,1))==size(A,2)),:)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I get the following result, which is what I want:

ans =

     1     4
     1     7
     4     7


However, if I increase the input A matrix to:

A = [    1     4     7;
           1      4     5 ]

How can I obtain:

result = 
                   1     4
                   1     7
                   4     7
                   1     4
                   1     5
                   4     5
                    
Please note that the last 3 rows in the 'result ' matrix can be obtained if I use A = [    1     4     5] as the input in my code.

How can I get this result  ?

thanks a lot
kurt
0
Reply Kurt 10/18/2010 5:43:04 AM

Hi,

Can anyone suggest how I may address this problem? I am not sure but is a  'for loop' required for situations as these?

thanks
kurt
0
Reply Kurt 10/18/2010 4:20:04 PM

NPERMUTEK finds the permutations with repetition.  What you are finding is the combinations without repetition.  I would therefore use NCHOOSEK, a MATLAB built-in.



nchoosek( [ 1 4 7],2)
0
Reply Matt 10/18/2010 5:17:05 PM

4 Replies
416 Views

(page loaded in 0.043 seconds)

Similiar Articles:













7/24/2012 12:22:45 PM


Reply: