行列の中で範囲内の値の数を求めたい

4 vues (au cours des 30 derniers jours)
kuroshiba
kuroshiba le 17 Fév 2023
Commenté : kuroshiba le 10 Mar 2023
[14,5,11;15,10,6;5,12,9]のように3×3行列、9個の要素がある中、9以上20以下の要素は何個あるかを知りたいんですが、どのようなプログラムが必要なのでしょうか。
ご教授いただけると幸いです。

Réponse acceptée

Atsushi Ueno
Atsushi Ueno le 17 Fév 2023
A = [14,5,11;15,10,6;5,12,9]
A = 3×3
14 5 11 15 10 6 5 12 9
TF = (A>=9 & A<=20) % 9以上20以下の要素
TF = 3×3 logical array
1 0 1 1 1 0 0 1 1
sum(TF,'all') % 9以上20以下の要素は何個あるかを知りたい
ans = 6
  1 commentaire
kuroshiba
kuroshiba le 10 Mar 2023
ありがとうございます!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur データ型 dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!