How do I pick selected values in a matrix

1 vue (au cours des 30 derniers jours)
NAA
NAA le 27 Mar 2023
Commenté : NAA le 27 Mar 2023
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 commentaires
the cyclist
the cyclist le 27 Mar 2023
Modifié(e) : the cyclist le 27 Mar 2023
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 le 27 Mar 2023
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

Connectez-vous pour commenter.

Réponse acceptée

the cyclist
the cyclist le 27 Mar 2023
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

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by