-1

How do you generate a matrix with a predefined probability of occurrence for each possible value? For example, I need to generate a 3-by-5 matrix consisting of only 1, 0 and -1, where the probability of occurrence of 1 is 0.25, the probability of occurrence of -1 is 0.25 and the probability of occurrence of 0 is 0.5?

Dan
  • 45,079
  • 17
  • 88
  • 157
rose
  • 1

1 Answers1

0

The simple answer is:

round(rand(3,5)*2)-1

more generally you have to find a function that produces random variables according to your probability distribution. Then you can use reshape() to get the right array.

Dennis Klopfer
  • 759
  • 4
  • 17