【发布时间】:2009-11-29 17:16:40
【问题描述】:
我使用此代码创建和绘制N 点:
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
我如何随机选择这些点之一?
【问题讨论】:
标签: matlab
我使用此代码创建和绘制N 点:
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
我如何随机选择这些点之一?
【问题讨论】:
标签: matlab
【讨论】:
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.
【讨论】:
0(不能用作索引)并且很少(如果有的话)生成值N。
randnum = floor(rand(1)*N) + 1;,因为rand 生成的数字 u 具有 0
只要拿第一个。作为 rand() 函数的产物,它对任何人来说都应该足够随机:-)
plot(x(1),y(1),'o');
【讨论】: