Hi,I have numerical matrix 4X4, I have to classify numbers in grades like less than 20, greater than 20 and less than 20, so Hhow can I do it?

I have numerical matrix 4X4, I have to classify numbers in grades like less than 20, greater than 20 and less than 20, so how can I do it?

 採用された回答

Thorsten
Thorsten 2015 年 10 月 16 日
X = randi(30, [4 4])
g20 = X(X > 20)
le20 = X(X <=20)

その他の回答 (1 件)

Jack Breenlair
Jack Breenlair 2015 年 10 月 16 日
編集済み: Jack Breenlair 2015 年 10 月 16 日
You want to use two for loops that go through the matrix checking if the numbers satisfy the conditions that you require.
auxiliar=0;
for i=1:4
for j=1:4
if A(i,j)==condition
auxiliar=auxiliar+1;
end
end
end
something like this

3 件のコメント

The code above can be reduced simply to:
auxiliar = nnz(A == condition);
No need for loops.
Anup Badve
Anup Badve 2015 年 10 月 16 日
Thank you Guillaume !
Anup Badve
Anup Badve 2015 年 10 月 16 日
Thank you Jack !

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

カテゴリ

ヘルプ センター および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

質問済み:

2015 年 10 月 16 日

コメント済み:

2015 年 10 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by