Count Numbers between two values in random vectors

39 vues (au cours des 30 derniers jours)
Hadi
Hadi le 6 Jan 2015
Commenté : Logan Calkins le 4 Juil 2021
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?

Réponse acceptée

Titus Edelhofer
Titus Edelhofer le 6 Jan 2015
Hi,
use logical indexing and count the result:
X = rand(1, 1000);
nBetween05and09 = sum(X>0.5 & X<0.9)
Titus
  3 commentaires
Samreen Aziz
Samreen Aziz le 13 Avr 2021
This works :)
Logan Calkins
Logan Calkins le 4 Juil 2021
Thanks

Connectez-vous pour commenter.

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 6 Jan 2015
find(A==5)-find(A==1)-1
  2 commentaires
Hadi
Hadi le 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.
Thanks
Torsten
Torsten le 6 Jan 2015
Examples: Histogram of a vector.
Best wishes
Torsten.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by