data = rand(N,2); %# generate random points
index = (rand(N,1) <= p); %# roll coins to pick with prob p
data(~index, :) = []; %# keep only selected points
plot(x(index),y(index),'r*');
dist=sqrt((data(1,1)-data(~index,1))^2+(data(1,2)-data(~index,2))^2); % ques is what to put for data(~index,:) 's first or any element?
If we have to find distance between any point of data=rand(N,2) (say first) from any point of data(~index, :) = []; (say first of this also), how can we use data(~index, :) = []; matrix in following statement?
dist=sqrt((data(1,1)-data(~index,1))^2+(data(1,2)-data(~index,2))^2)
My question is as we are taking first element of data as data(1,1) and data (1,2), how do we take take first element of data(~index,:) matrix?
I’m not quite sure what you want to do.
The command
data(~index, :) = []removes all rows for which the random number is larger than p, so after that commanddatawill no longer be an N-by-2 matrix but it will be a smaller matrix. I’ll assume you won’t give that command, because afterwards you can no longer refer to the points indatathat were removed.If you want to take the distance between the first point in
dataand the first point indataselected by the random coin throw, one possibility is to use thefindfunction (look it up to see what it does):The last line can also be written as:
If you want something else, please explain.