Populate an array with n number of points based on probability

5 views (last 30 days)
I have a 15x15 array filled with values ranging from 0 to 10. This is my probability array.
I want to create a second 15x15 array and populate it with 25 points that are 'randomly' generated, except I want the cells with higher values in the probability array to have a higher chance of generating one of the 25 points.
The probability array represents the z values from a surface I have plotted so in principal what I'm trying to do is fit a probability distribution function to a non-uniform, non-normal 3D surface and then use this to generate points. But in a simple manner.
  2 Comments
KALYAN ACHARJYA
KALYAN ACHARJYA on 6 Nov 2019
Sorry I did mot get the question, can you elaborate with examples?
Samuel Mousley
Samuel Mousley on 6 Nov 2019
I dont yet have anything to show as an example I'm afraid but I will try elaborate.
I'm essentailly trying to gererate a 15x15 array of zeros with 25 randomly distributed 1's (points). I can do this easily using the 'randi' function.
n = 25;
xy = randi([1 15], n, 2)
xy =
14 8
12 7
5 15
12 4
3 10
.
.
.
I would then use these randomly generated values as coordinates to index my 15x15 array to choose 25 points.
However, I dont want a truly random distribution of points, I want to specify that some coordinates of the array are more likely to be chosen than others. This is where my 15x15 array of values comes in. (I have attached an image of this).
I want to use the values of this array to specify the probability of each of the coordinates being chosen. i.e, cells with a 0 have a zero chance of a point being chosen, and cells with a 10 are ten times more likely to be chosen than a cell with a 1.
I hope this helps!

Sign in to comment.

Accepted Answer

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH on 6 Nov 2019
solution:
array15x15filled0to10=randi([0,10],15);%put your data probability array here
arraypoints=zeros(15);
n = 25;
xy = randi([1 15], n, 2);
index=datasample(1:numel(arraypoints),n,'Replace',false','Weights',array15x15filled0to10(:));%here the solution
arraypoints(index)=1%populate it with 25 points dependent on the probability matrix

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!