exstract consecutive duplicate element of array

Dear Dear I've got the folowing problem Given an A matrix nxm i need to exstract consecutive duplicate elements of array
so I mean if for excample the row n=n+1 =n+2 I want to get a matrix B obtainet from A less the rows duplicate

댓글 수: 4

Example of your output?
ADC
ADC 2018년 10월 25일
편집: Guillaume 2018년 10월 25일
For exsamples the second coloumn the secon line have the value 2 duplicate
so the functions i need is to get te matrix B as following
A =
1 2 3
1 2 7
3 4 9
K>> B=[1 2 3;3 4 9]
B =
1 2 3
3 4 9
jonas
jonas 2018년 10월 25일
편집: jonas 2018년 10월 25일
I think you missed some ;'s there? Should it be
A = [1 2 3; 1 2 7; 3 4 9]
and the output
B = [1 2 3; 3 4 9]
?? I'm just guessing here
ADC
ADC 2018년 10월 25일
yess

댓글을 달려면 로그인하십시오.

답변 (2개)

Stephen23
Stephen23 2018년 10월 25일

1 개 추천

>> A = [1,2,3;1,2,7;3,4,9;9,9,9;7,7,7]
A =
1 2 3
1 2 7
3 4 9
9 9 9
7 7 7
>> B = A([true;all(diff(A,1,1)~=0,2)],:)
B =
1 2 3
3 4 9
7 7 7
jonas
jonas 2018년 10월 25일
편집: jonas 2018년 10월 25일

0 개 추천

A is your matrix. This line removes duplicates:
A([false diff(A)==0]) = [];
Or you could expand it to this, given your vague example from the comments
A =
1 2 3
1 2 7
3 4 9
_
mask = [ones(1,size(A,1));diff(A,1)] == 0;
A = A(sum(mask,2)==0,:)
A =
1 2 3
3 4 9

댓글 수: 2

ADC
ADC 2018년 10월 25일
this is exsactly what I need but I whant that this check is done only for example a given coulumn, for example the coloumn 3
jonas
jonas 2018년 10월 25일
편집: jonas 2018년 10월 25일
Simple enough, just change this line
mask = [false;diff(A(:,3))==0]
or simply write it like this
mask = [false;diff(A(:,3))==0]
A = A(~mask,:)
The number, in this case 3, determines the column over which the check is made

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

ADC
2018년 10월 25일

편집:

2018년 10월 25일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by