How do I pick selected values in a matrix
3 views (last 30 days)
Show older comments
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
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.
Accepted Answer
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")
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!