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:
how to remove repeated shifted rows in a matrix

Subject: how to remove repeated shifted rows in a matrix

From: ratnesh

Date: 25 Aug, 2009 13:15:06

Message: 1 of 2

here i want to remove repeated shifted version of matrix row.
column may can vary here is 4 may be it will 3,5etc.

2 1 1 7==>(1)
2 1 2 6
1 1 7 2==>repeated as (1) that is shifted,,need to remove it
1 1 3 6
3 1 1 6
3 1 2 5
3 1 3 4
3 2 4 2==>(2)
2 3 1 5
2 3 2 4==>repeated as (2) that is shifted,,need to remove it


or
matrix is
     1 1 1 8
     1 1 2 7
     1 1 3 6
     1 1 4 5
     1 2 1 7
     1 2 2 6
     1 2 3 5
     1 2 4 4
     1 3 1 6
     1 3 2 5
     1 3 3 4
     1 4 1 5
     1 4 2 4==>(1)
     2 1 1 7
     2 1 2 6
     2 1 3 5
     2 1 4 4
     2 2 1 6
     2 2 2 5
     2 2 3 4
     2 3 1 5
     2 3 2 4
     2 3 3 3
     2 4 1 4==>repeated as (1) that is shifted to previous,,need to remove it
     3 1 1 6
     3 1 2 5
     3 1 3 4
     3 2 1 5
     3 2 2 4
     3 3 1 4
     4 1 1 5

thanks

Subject: how to remove repeated shifted rows in a matrix

From: Avni Pllana

Date: 26 Aug, 2009 09:44:11

Message: 2 of 2

> here i want to remove repeated shifted version of
> matrix row.
> column may can vary here is 4 may be it will 3,5etc.
>
> 2 1 1 7==>(1)
> 2 1 2 6
> 1 1 7 2==>repeated as (1) that is
> shifted,,need to remove it
> 1 1 3 6
> 3 1 1 6
> 3 1 2 5
> 3 1 3 4
> 3 2 4 2==>(2)
> 2 3 1 5
> 2 3 2 4==>repeated as (2) that is
> shifted,,need to remove it
>
>
> or
> matrix is
> 1 1 1 8
> 1 1 2 7
> 1 1 3 6
> 1 1 4 5
> 1 2 1 7
> 1 2 2 6
> 1 2 3 5
> 1 2 4 4
> 1 3 1 6
> 1 3 2 5
> 1 3 3 4
> 1 4 1 5
> 1 4 2 4==>(1)
> 2 1 1 7
> 2 1 2 6
> 2 1 3 5
> 2 1 4 4
> 2 2 1 6
> 2 2 2 5
> 2 2 3 4
> 2 3 1 5
> 2 3 2 4
> 2 3 3 3
> 2 4 1 4==>repeated as (1) that is
> at is shifted to previous,,need to remove it
> 3 1 1 6
> 3 1 2 5
> 3 1 3 4
> 3 2 1 5
> 3 2 2 4
> 3 3 1 4
> 4 1 1 5
>
> thanks

Hi Ratnesh,

here is a function that does the work:

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

function B=removecircshift(A)
%
% Removes repeated shifted rows in matrix A.
 
sA=size(A);
 
n1=1;
n2=2;
 
while 1
    C=[];
    for i=n2:sA(1)
        for j=1:sA(2)
            m=ismember(A(n1,:),circshift(A(i,:),[0, j-1]),'rows');
            if m
                C=[C i];
                break
            end
        end
    end
    A(C,:)=[];
    n1=n1+1;
    n2=n2+1;
    sA=size(A);
    if n2>sA(1)
        break
    end
end
B=A;

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

Best regards,
    Avni

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