How can I count the number of times a specific value appears within a range in a 1D vector?

Given a 1D vector, x, that has 600000 elements, how can I count the number of times the value 1 appears after the 150th position (excluding 150)?

추가 답변 (2개)

Ameer Hamza
Ameer Hamza 2020년 4월 27일
편집: Ameer Hamza 2020년 4월 27일
Try this.
x = randi([1 10], 1, 600000); % random vector
result = sum(x(151:end)==1);
If x is a vector of whole numbers
sum( double( x(151:end)==1 ) )
else
sum( double( abs(x(151:end)-1) < small_number ) )

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

질문:

2020년 4월 27일

댓글:

2020년 4월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by