How can I select three random sample of a matrix with minimum separation between samples?

7 views (last 30 days)
Hi everyone,
I have the following problem: I have a matrix A(20x20) per example and I need select from this matrix 3 random samples that have to be different and with a minimum separation (distance) between samples. I mean that between samples chosen randomly, would exist a minimum separation of 4 samples, per example the sum of 3 samples to the right in the same row and 1 sample up in the column.
There exists a way to obtain this?
I have been trying to get this using the following, but if I repeat it 3 times, exists the probability to get the same sample. Also I don't know how to get the restriction of the minimum separation.
random_sample1 = A(randi(numel(A)))
Thank you very much in advance for your help.
J.F.
  2 Comments
James Tursa
James Tursa on 8 Feb 2021
Edited: James Tursa on 8 Feb 2021
You may need to do this either sequentially or with a rejection method to satisfy your distance requirement.
Javier Fuster
Javier Fuster on 8 Feb 2021
Yes, I think so. I was wondering if there was a method more robust than start to reject putting so many 'if'.
Also, thank you for your response.

Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 8 Feb 2021
A rejection method is straightforward. Simply make your selections in a forever loop until you get something that works. The advisibility of this approach depends on the probability of getting a rejection. E.g., rejection method code for generating one sample set
n = numel(A);
nsamples = 3;
dmin = 4;
while( true )
sample_indexes = randperm(n,nsamples);
[row,col] = ind2sub(size(A),sample_indexes);
d = abs(row - row') + abs(col-col');
d(1:nsamples+1:end) = inf;
if( all(d(:)>=dmin) )
break;
end
end
samples = A(sample_indexes);
This assumes there is no wrap-around for row & column comparisons.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!