Check if random (x,y) coordinates exist in separate x vector and y vector

4 views (last 30 days)
I have a vector of x coordinates (called circox) and a vector of corresponding y coordinates (called circoy). I then generate a random x and y coordinate and need to check if these coordinates already exist as a pair in circox and circoy. If they already exist I will reject them. In pseudo code I am trying to achieve this:
circox = (x1, x2, x3, ...40 values)
circoy = (y1, y2, y3, ...40 values)
x = rand
y = rand
if ((x,y) appears as a pair in (circox,circoy)),
reject x and y;
else
accept x and y;
end
Just need to figure out the if part. In theory I could loop through each position in circox and circoy, checking if it matches the randomly generated (x,y) coordinates but I'm hoping there's a neater function built into MATLAB.
Any ideas?

Accepted Answer

Walter Roberson
Walter Roberson on 9 Apr 2014
ismember() with the 'rows' option.

More Answers (0)

Categories

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

Community Treasure Hunt

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

Start Hunting!