MATLAB: How to flip some elements of a matrix having 0 and 1 with a given probability

flipmatrixprobability

I have a row matrix with elements 0 and 1. I want to transmit this this row such that at the output all 0s should remain 0 and !s should be flipped to 0 with a probability of 0.01

Best Answer

data = randi([0,1], 1, 100);
index = (data == 1);
data(index) = (rand(1, sum(index)) > 0.01); % or >= ?