如何在MATLAB中从N个点中随机选择一个点? [英] How would I randomly pick one point from N points in MATLAB?

查看:327
本文介绍了如何在MATLAB中从N个点中随机选择一个点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码创建和绘制N点:

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. 

这篇关于如何在MATLAB中从N个点中随机选择一个点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆