How do I randomly select k points from N points in MATLAB? -


I use this code to create and filter the N points:

  n = input ('number of nodes:'); Data = rand (n, 2)% randomly generated n Nodes x = data (:, 1); Y = data (:, 2); Plot (x, y, '*'); How can I choose the  k  point (with probability  p = 0.25 ) outside of the  n  points, then those  k  Paint the dots and leave the other points as  * . 

You can take two methods that you can do the first solution randomly k Choosing N values ​​from values, will ensure that you have selected always near k . The second solution is to take the values ​​randomly, with the average probability p to be selected, which can be as low as 0 or as many as Sorting as N is being selected randomly.

You can use the function to create a random permutation of N via code> 1 , then select the first code sorted list and copy them as red :

  index = randosperm (n); Plot (x (index (1: k)), y (index (1: t)), 'r *');  
  • Choosing values ​​with the average probability p :

    you use You can do this to get a random value from 0 to 1 for each of your N values, then select those people whom Copy to a random value or your average probability p and copy it as red:

      index = (rand (n, 1)  

  • Comments

    Popular posts from this blog

    c# - How to capture HTTP packet with SharpPcap -

    php - Multiple Select with Explode: only returns the word "Array" -

    jquery - SimpleModal Confirm fails to submit form -