How would I randomly pick one point from N points in MATLAB?

前端 未结 3 1087
自闭症患者
自闭症患者 2020-12-21 13:24

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);
         


        
3条回答
  •  没有蜡笔的小新
    2020-12-21 14:11

    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. 
    

提交回复
热议问题