Count Numbers between two values in random vectors
41 次查看(过去 30 天)
显示 更早的评论
I am trying to find the how many numbers are between two specific values in a random vector. For example, How many are betweens 1 and 5
A=[1,2,3,4,5]
is should return 3 in this case. So what is the function that allow me to identify this?
0 个评论
采纳的回答
Titus Edelhofer
2015-1-6
Hi,
use logical indexing and count the result:
X = rand(1, 1000);
nBetween05and09 = sum(X>0.5 & X<0.9)
Titus
3 个评论
更多回答(1 个)
Azzi Abdelmalek
2015-1-6
find(A==5)-find(A==1)-1
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!