MATLAB Answers

Count Numbers between two values in random vectors

64 views (last 30 days)
Hadi on 6 Jan 2015
Commented: Hadi on 6 Jan 2015
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
is should return 3 in this case. So what is the function that allow me to identify this?


Sign in to comment.

Accepted Answer

Titus Edelhofer
Titus Edelhofer on 6 Jan 2015
use logical indexing and count the result:
X = rand(1, 1000);
nBetween05and09 = sum(X>0.5 & X<0.9)

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 6 Jan 2015


Hadi on 6 Jan 2015
I have a random vector, so t did not work in my case. In other words, e.g X=rand(1,1000) and I want to find how many between 0.5 and 0.9. Would it be the same method you provided? can you help me.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!