Clear Filters
Clear Filters

index 1-0 sume set

1 view (last 30 days)
Marek Drliciak
Marek Drliciak on 24 Aug 2022
Commented: Dyuman Joshi on 24 Aug 2022
Hello,
chcel by som poprosiť o radu k tvorbe množín. Mám vektor s more than 10000 values. Data obsahujú value 1 an 0 (yes/NO).
Potrebujem určiť početnosť množín po sebe idúcich hodnôt 1. Napríklad: Koľko krát sa vyskytuje množina s tromi hodnotami 1 za sebou?
01011101111011101
V príklade vyšie je odpoveď 2.
Takto potrebujem určiť početnosť s výskytom 1 až x
Thank You

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 24 Aug 2022
Edited: Dyuman Joshi on 24 Aug 2022
Writing the answer based on Google translate text
x=[0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 0 1];
x=[~x(1) x ~x(end)];
c=0; %count
n=3; %set with n consecutive values of 1
for i=n+1:numel(x)-1
if sum(x(i-n+1:i))==n & ~x(i-n) & ~x(i+1) %exactly n values consecutively only
c=c+1;
end
end
c
c = 2
  3 Comments
Bruno Luong
Bruno Luong on 24 Aug 2022
The code crashes for
x=[1 1 1 0 1 1 1 1 0 1 1 1];
Dyuman Joshi
Dyuman Joshi on 24 Aug 2022
Thanks for pointing out, Bruno. I have edited my code accordingly.

Sign in to comment.

More Answers (0)

Categories

Find more on Particle & Nuclear Physics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!