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?

 採用された回答

Titus Edelhofer
Titus Edelhofer 2015 年 1 月 6 日

6 投票

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

3 件のコメント

Hadi
Hadi 2015 年 1 月 6 日
thanks
Samreen Aziz
Samreen Aziz 2021 年 4 月 13 日
This works :)
Logan Calkins
Logan Calkins 2021 年 7 月 4 日
Thanks

サインインしてコメントする。

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 1 月 6 日

0 投票

find(A==5)-find(A==1)-1

2 件のコメント

Hadi
Hadi 2015 年 1 月 6 日
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 2015 年 1 月 6 日
Examples: Histogram of a vector.
Best wishes
Torsten.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by