필터 지우기
필터 지우기

create a matrix that keeps only the sequential numbers

조회 수: 2 (최근 30일)
Alberto Acri
Alberto Acri 2023년 8월 3일
답변: Stephen23 2023년 8월 3일
Hi! I need to create a matrix that keeps only the sequential numbers in the first column (and keep the corresponding number in the second column) and delete everything else. Here is an example:
  댓글 수: 3
Akira Agata
Akira Agata 2023년 8월 3일
What happens if the 1st column consists of two sequential numbers, like: [1 2 3 4 7 8 9 10]' ?
Alberto Acri
Alberto Acri 2023년 8월 3일
@Stephen23 If there are two or more sets of sequential numbers, I would like to keep all sequences of at least 2 sequential numbers. So if the first column is: [77; 78; 79; 81; 83; 84; 94] it would become: [77; 78; 79; 83; 84]. Or if the first column is: [77; 78; 79; 81; 82; 83; 84] it would remain the same.
@Akira Agata In the case you wrote, the column would remain the same.

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

채택된 답변

Stephen23
Stephen23 2023년 8월 3일
S = load('CountArray_A_zoom_select.mat');
A = S.CountArray_A_zoom_select
A = 9×2
77 769 78 513 79 412 80 331 81 297 82 182 83 116 84 76 94 64
X = diff(A(:,1))==1;
Y = [X;0]|[0;X];
B = A(Y,:)
B = 8×2
77 769 78 513 79 412 80 331 81 297 82 182 83 116 84 76

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by