How do I find the number of occurrences of data points between specified values in a matrix?

1 次查看(过去 30 天)
I am trying to find the interval of data point occurrences in a 1x40 matrix.
given:
x=[1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 3 3 4 5 6 1 2 2 2 2 2 2 2 2 2 2 2 3 4 1 2 2 2 2 2];
I want to find the number of values between the 1's found in this data set. The output should say how many occurrences of "1" exist (4) and the number of data points that occur before the next "1" in sequence. For example, between the first and second "1" =9, between the second and third "1=9", between the third and fourth "1"=13.
Any help would be appreciated!

采纳的回答

Andrei Bobrov
Andrei Bobrov 2015-12-8
编辑:Andrei Bobrov 2015-12-8
t = x == 1;
out = diff(find(t))-1;
  2 个评论
Joe
Joe 2015-12-8
How could one change this code to determine specific data points to choose between? for example.
x=[4 1 2 2 2 2 2 2 2 2 2 4 1 2 2 2 2 3 3 4 5 6 1 2 2 2 2 2 2 2 2 2 2 2 3 4 1 2 2 2 2 2];
If I had this code and I wanted to find the interval between the "1" and the next "4" in sequence how would I go about doing it? I want the code to output the interval of data points between the two specific values for each of the occurrences. From the data given as X the output should be output=[9 6 13]
Any help would be appreciated

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by