Populate an array with n number of points based on probability
5 views (last 30 days)
Show older comments
Samuel Mousley
on 6 Nov 2019
Commented: Samuel Mousley
on 6 Nov 2019
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
Accepted Answer
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)
See Also
Categories
Find more on Creating and Concatenating Matrices 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!