How can I count the number of times a specific value appears within a range in a 1D vector?
2 次查看(过去 30 天)
显示 更早的评论
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)?
0 个评论
采纳的回答
更多回答(2 个)
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);
per isakson
2020-4-27
If x is a vector of whole numbers
sum( double( x(151:end)==1 ) )
else
sum( double( abs(x(151:end)-1) < small_number ) )
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!