# grouping first (left column) and last (right column) of consecutive sequence of a Nx2 matrix

조회 수: 1 (최근 30일)
Paramonte 2019년 1월 24일
답변: Paramonte 2019년 1월 24일
Hi there
We have a Nx2 matrix with pieces of consecutive values that we want to obtain the extreme left and right limits:
A=[100 200; 101 201; 102 202; 300 400; 801 901; 802 902]
we would like to obtain a matrix with limits (left column and right column) in the detected consecutive sequences of the first column. The isolated sequences (in this case [300 400] should be also retrieved.
for A the result would be;
B=[100 202; 300 400; 801 902] ;

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

### 채택된 답변

Guillaume 2019년 1월 24일
You haven't clearly defined what consecutive values means mathematically. I'm assuming a difference of 1. Also you haven't explained if both columns are to be considered independently (and what happen if values are consecutive in one column and not the others). I'm assuming that both columns have the exact same pattern so we can ignore column 2 for finding consecutive values.
A=[100 200; 101 201; 102 202; 300 400; 801 901; 802 902];
%finding start and end of consecutive runs. Only using 1st column for that
transitionrows = find(diff([-Inf; A(:, 1); +Inf]) ~= 1); %not consecutive when difference is not 1
startseqrows = transitionrows(1:end-1); %start row of consecutive run
endseqrows = transitionrows(2:end) - 1; %end row of consecutive run
B = [A(startseqrows, 1), A(endseqrows, 2)]

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

### 추가 답변 (1개)

Paramonte 2019년 1월 24일
Many thanks it worked perfectely!!
Best Regards

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

### 카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by