How do I pick selected values in a matrix

2 visualizzazioni (ultimi 30 giorni)
NAA
NAA il 27 Mar 2023
Commentato: NAA il 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 Commenti
the cyclist
the cyclist il 27 Mar 2023
Modificato: the cyclist il 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 il 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

Accedi per commentare.

Risposta accettata

the cyclist
the cyclist il 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

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by