Populate an array with n number of points based on probability

조회 수: 6 (최근 30일)
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
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 11월 6일
Sorry I did mot get the question, can you elaborate with examples?
Samuel Mousley
Samuel Mousley 2019년 11월 6일
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!

댓글을 달려면 로그인하십시오.

채택된 답변

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019년 11월 6일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by