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

조회 수: 17 (최근 30일)
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일
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개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by