Find the total number of values between alimits

2 ビュー (過去 30 日間)
navan
navan 2015 年 5 月 7 日
編集済み: Stephen23 2015 年 5 月 7 日
I have a matrix A= [1,2,3,4,5,6,7,8,9,10,11]. I would like to find out total number of elements which are greater that 3 and less than 10. expected answer is no of values between 3 &10 is= 6.
I have used formulae no of values =sum(A(:) == 3<A<10)); but it showing error.

採用された回答

Michael Haderlein
Michael Haderlein 2015 年 5 月 7 日
you were close:
>> A= [1,2,3,4,5,6,7,8,9,10,11];
>> sum(A>3 & A<10)
ans =
6

その他の回答 (1 件)

Purushottama Rao
Purushottama Rao 2015 年 5 月 7 日
sum(3<A)-sum(A>=10)
USE THIS
  1 件のコメント
Stephen23
Stephen23 2015 年 5 月 7 日
編集済み: Stephen23 2015 年 5 月 7 日
Michael Haderlein's solution is more robust and general solution, e.g. it gives the correct result (zero) when the bounds are swapped:
>> sum(7<A)-sum(A>=5)
ans =
-3
>> sum(A>7 & A<5)
ans =
0

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

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by