MATLAB: Matrix multiplication with probability

probabilty of multiplication for each values in a 3x3 matrix

Hi, I want to assign a probability of multiplication for each value in a 3X3 matrix and multiply it by a random number. Can anyone please help me with this.

Best Answer

If p is a matrix the same size as A with the probability values you describe, do this:
SA = size(A);
a = rand(SA);
A = A + (A.*a-A).*(rand(SA)<=p);
At each element of A it is multiplied by the random number in ’a’ with probability in the corresponding element in p. Otherwise the element is unchanged.
It is possible you meant 'a' to be a single random scalar value rather than a matrix of them. If so, change the code to:
a = rand;
A = A + ((a-1)*A).*(rand(size(A))<=p);