find observations with nonconsecutive numbers

8 次查看(过去 30 天)
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
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.

请先登录,再进行评论。

类别

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