Replacing n random zeros in a matrix with a specific nonzero value
3 views (last 30 days)
Show older comments
Commented: Jerrold Tubay on 2 Oct 2020
Suppose I start with a zero matrix
X = zeros(100)
How can I replace n random zeros in matrix X with a single nonzero value (e.g., replace 10 zero elements in the matrix X with 1)?
madhan ravi on 2 Oct 2020
X(randperm(numel(X), 10)) = 1
More Answers (0)
Find more on Logical 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!