필터 지우기
필터 지우기

find observations with nonconsecutive numbers

조회 수: 8 (최근 30일)
wesso Dadoyan
wesso Dadoyan 2017년 7월 8일
답변: Walter Roberson 2017년 7월 8일
A=[55; 56; 57; 58; 26; 27; 28]
I want to find the observations in A where the two consecutive observations are not equal. In this case it should be the 5th observation since 26~=58. How can I do that elegantly?

채택된 답변

Walter Roberson
Walter Roberson 2017년 7월 8일
find(diff(A) ~= 1) + 1

추가 답변 (1개)

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2017년 7월 8일
like this:
A=[55; 56; 57; 58; 26; 27; 28];
observations=A([1; diff(A)]~=1);
  댓글 수: 2
wesso Dadoyan
wesso Dadoyan 2017년 7월 8일
these codes are giving 26 instead of 5. I don't want the value but rather the row number.
JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2017년 7월 8일
A=[55; 56; 57; 58; 26; 27; 28];
observations=find([1; diff(A)]~=1);

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

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by