I use this code to create and plot N
points:
N = input('No. of Nodes:');
data = rand(N,2); % Randomly generated n no. of nodes
x = data(:,1);
y = data(:,2);
plot(x,y,'*')
hold on
How would I randomly pick one of these points?
I use this code to create and plot N
points:
N = input('No. of Nodes:');
data = rand(N,2); % Randomly generated n no. of nodes
x = data(:,1);
y = data(:,2);
plot(x,y,'*')
hold on
How would I randomly pick one of these points?
randnum=ceil(rand(1)*N) %Sample a random integer in the range 0 to N
your_node = [x(randnum),y(randnum)] %Here is the sampled node from your data set
Edit: changed floor to ceil.
You can use the function RANDI to generate a random integer in a given range:
index = randi(N); %# Generate a random integer in the range 1 to N
plot(x(index),y(index),'o'); %# Plot the point
EDIT: As pointed out by Mikhail, the RANDI function has only been available since version 7.7 (R2008b). For earlier versions, the following alternative should work:
index = ceil(rand*N);
Just take the first one. Being a product of the rand()-function, it should be random enough for anybody :-)
plot(x(1),y(1),'o');