필터 지우기
필터 지우기

Find 625 consecutive ones in vector

조회 수: 1 (최근 30일)
Sam
Sam 2020년 3월 24일
편집: John D'Errico 2020년 3월 24일
Hello,
I have a 45000x1 rowvector, which contains only 1's and 0's. I want to find the periods of 625 consecutive ones and locations of these 1's in this vector. Can anyone help?
Thank you.
  댓글 수: 2
Sean de Wolski
Sean de Wolski 2020년 3월 24일
편집: Sean de Wolski 2020년 3월 24일
Exactly 625 or >=625?
John D'Errico
John D'Errico 2020년 3월 24일
편집: John D'Errico 2020년 3월 24일
As Sean points out, the difference might change how one solves the problem. Do you want to find ALL occurrences of exactly 625 ones? What if there is a string of length 626? Does that correspond to two sustrings of length 625, one starting one element further down the line? Or is that just one string, that happens to satisfy the goal? What if there was a string of length 1250? Is that two consecutive strings of length 625? Or is it 625 strings of length 625 that overlap, or is it just one string?

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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 3월 24일
편집: Ameer Hamza 2020년 3월 24일
The following code will find 3 consecutive ones in an input array and output the starting index of each occurrence
x = [0 1 1 1 0 0 1 1 0 1 1 1 0 1];
index = strfind(x, [1 1 1]);
output
index =
2 10

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by