finding value less than a threshold

Hi, suppose I have a matrix A as follows:
A =
1 2 3
3 3 6
4 6 8
4 7 7
I need to find the number of values of matrix A having value less than 6.
How to do this?
Thanks in advance

 採用された回答

Walter Roberson
Walter Roberson 2011 年 5 月 9 日

1 投票

sum(A(:)<6)

3 件のコメント

Mohammad Golam Kibria
Mohammad Golam Kibria 2011 年 5 月 9 日
this code gives the following output:
>> sum(A(:)<6)
ans =
7
but in the matrix values less than 6 are 1,2,3,3,3,4,4 ;
so the output should be 20;
code might not correct.would u pls check again.Thanks
RoJo
RoJo 2011 年 5 月 9 日
>> sum(A(A<6))
ans =
20
Your original question is phrased wrong though for the answer you wanted. Should be 'sum of values of matrix A'
Walter Roberson
Walter Roberson 2011 年 5 月 9 日
RoJo is correct. Your original question asked for the *number* of values, and that is what I answered. RoJo's code is good if you want the total of those values.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by