How do I pick selected values in a matrix

2 ビュー (過去 30 日間)
NAA
NAA 2023 年 3 月 27 日
コメント済み: NAA 2023 年 3 月 27 日
I have generated the following matrix:
A =
0 0 0 0 0 2 2 2 0 0 2
0 2 0 2 0 0 0 0 0 2 0
2 2 0 2 2 0 0 2 2 2 2
2 2 0 0 0 2 2 0 2 0 2
2 2 2 0 0 2 2 0 2 0 0
2 2 2 0 2 0 0 2 2 2 0
2 2 2 2 2 2 2 2 2 2 0
2 2 2 0 2 2 2 2 0 2 2
2 0 2 0 2 2 2 2 2 0 0
2 2 2 2 2 2 2 2 0 2 2
How do I only select the zero values in the matrix?
  2 件のコメント
the cyclist
the cyclist 2023 年 3 月 27 日
編集済み: the cyclist 2023 年 3 月 27 日
When you say, "only select the zero values", can you be specific about what you want the output to be? Don't just rephrase it as something like, "I only want the zeros". Say exactly what the output should be.
NAA
NAA 2023 年 3 月 27 日
I want to:
  1. select the zero values in the matrix
  2. divide the number of zero values by the number of elements in the matrix which I will use in a plot

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

採用された回答

the cyclist
the cyclist 2023 年 3 月 27 日
You want the fraction of zeros in the array?
A = ...
[0 0 0 0 0 2 2 2 0 0 2
0 2 0 2 0 0 0 0 0 2 0
2 2 0 2 2 0 0 2 2 2 2
2 2 0 0 0 2 2 0 2 0 2
2 2 2 0 0 2 2 0 2 0 0
2 2 2 0 2 0 0 2 2 2 0
2 2 2 2 2 2 2 2 2 2 0
2 2 2 0 2 2 2 2 0 2 2
2 0 2 0 2 2 2 2 2 0 0
2 2 2 2 2 2 2 2 0 2 2];
mean(A==0,"all")
ans = 0.3636
  1 件のコメント
NAA
NAA 2023 年 3 月 27 日
yes! thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by