MATLAB Answers

## Obtaining a list of (x, y) points that correspond to specific values of concentration that are chosen at random

Asked by Summer

### Summer (view profile)

on 20 May 2015
Latest activity Edited by Summer

### Summer (view profile)

on 20 May 2015
Accepted Answer by Thomas Koelen

### Thomas Koelen (view profile)

Hello,
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,t), and now from the results of the first run I need Matlab to "randomly" pick (x,y) points with the above condition. Also, note the dimensions of the results from the first Matlab run (which the random sampling should be based on): concentration changes with location and time and is 52x61x61, x is 1x61, y is 1x52, and time is 1x61.
I have previously asked this question, and got an answer that allows me to generate a random sample of concentrations that meet the condition, but I don't know how to make the association of these concentrations with the x,y, and t that correspond to these values as per the original Matlab results. For example, for a randomly chosen concentration with a value of 50, what is x and y at which this value is observed?
Would appreciate any suggestions on how to go about this.

#### 0 Comments

Sign in to comment.

## 1 Answers

Answer by Thomas Koelen

### Thomas Koelen (view profile)

on 20 May 2015
Edited by Thomas Koelen

### Thomas Koelen (view profile)

on 20 May 2015
Accepted Answer

clc
clear all
close all
NOP=10;
A=rand(52,61,61)*100;
B=0;
Z=0;
while length(B)<NOP
X=randi([1 52]);
Y=randi([1 61]);
T=randi([1 61]);
if A(X,Y,T)>10
Z=Z+1;
B(Z,1)=A(X,Y,T);
B(Z,2)=X;
B(Z,3)=Y;
B(Z,4)=T;
end
end
This should somewhat do what you want. (If I understand you correctly)
NOP is the number of points you want and A is the array that contains your data.

Summer

### Summer (view profile)

on 20 May 2015
Thanks for the response, Thomas. It worked.

Sign in to comment.