필터 지우기
필터 지우기

index 1-0 sume set

조회 수: 1 (최근 30일)
Marek Drliciak
Marek Drliciak 2022년 8월 24일
댓글: Dyuman Joshi 2022년 8월 24일
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

채택된 답변

Dyuman Joshi
Dyuman Joshi 2022년 8월 24일
편집: Dyuman Joshi 2022년 8월 24일
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
Bruno Luong
Bruno Luong 2022년 8월 24일
The code crashes for
x=[1 1 1 0 1 1 1 1 0 1 1 1];
Dyuman Joshi
Dyuman Joshi 2022년 8월 24일
Thanks for pointing out, Bruno. I have edited my code accordingly.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Directed Graphs에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by