MATLAB: Generating a random list of (x, y) points that satisfy a condition

2dconditionrandomx and y

So I need to generate a matrix of points given that they meet the condition that at these (x,y) points concentration is greater than 10. Note that I first run a code that gives me concentration at each location c(x,y), and now from the results of the first run I need Matlab to "randomly" pick (x,y) points with the above condition.
Would appreciate any suggestions on how to go about this.

Best Answer

Try using thresholding and randperm():
% Generate sample data:
c = randi(40, 9, 9)
% Get a column vector of only those c that are more than 10.
moreThan10 = c(c>10) % Threshold data
% Get 5 indexes at random from moreThan10
randomIndexes = randperm(length(moreThan10), min([5, length(moreThan10)]))
% Extract those 5 random indexes from our list into a new array called output.
output = moreThan10(randomIndexes)