Finding the number of values bigger than a certain number in an array?

Suppose I have an array of 50 numbers, how would I find the number of elements bigger than say 21 in an array of random numbers? Conversely, for less than as well.

 採用された回答

Tom
Tom 2012 年 9 月 26 日
編集済み: Tom 2012 年 9 月 26 日

0 投票

x=50*rand(7);
a= x > 21;
numel(a(a>0))

2 件のコメント

Jan
Jan 2012 年 9 月 26 日
編集済み: Andrei Bobrov 2012 年 9 月 26 日
Or: sum(a(:) > 0)
Image Analyst
Image Analyst 2012 年 9 月 26 日
編集済み: Andrei Bobrov 2012 年 9 月 26 日
Or
numberBigger = sum(x(:)>21);
numberSmaller = sum(x(:)<=21);

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by