create a matrix that keeps only the sequential numbers
조회 수: 2 (최근 30일)
이전 댓글 표시
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1449102/image.png)
댓글 수: 3
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]' ?
채택된 답변
Stephen23
2023년 8월 3일
S = load('CountArray_A_zoom_select.mat');
A = S.CountArray_A_zoom_select
X = diff(A(:,1))==1;
Y = [X;0]|[0;X];
B = A(Y,:)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!