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
채택된 답변
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 Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!