How do I pick selected values in a matrix

3 views (last 30 days)
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 Comments
the cyclist
the cyclist on 27 Mar 2023
Edited: the cyclist on 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 on 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

Sign in to comment.

Accepted Answer

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

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!