For example, I want Matlab to tell me the position in my vector of where I have 4 ones in a row for example which here would be indices 10 to 14
Count repetitions separately in an array
조회 수: 2 (최근 30일)
이전 댓글 표시
I have this array
A = [1;1;2;2;2;2;2;2;3;1;1;1;1;4;4;4;1;1;1;5;5];
I want Matlab to tell me when the repetition of 1 is greater than 2 for example, but I don't know any function that does this.
Could you help ? Thanks a lot !
채택된 답변
추가 답변 (1개)
Antoni Garcia-Herreros
2023년 3월 17일
Hello Lea,
Try something like this:
% Where 1 would be the number you are looking and 2 the number of repeats
sum(A==1)>2 % True if there are more than two instances of 1 in your array
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!