matlab随机选择数据的问题
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/19 16:40:10
matlab随机选择数据的问题
对两个满足二维正态分布的二维数组,如何从中分别随机选出N个数据.
对不起,我好像说的不太准确,应该是两个数组,每个数组中的元素是(x,y).麻烦各位了……
mu = [2 3];
SIGMA = [3 0; 0 3];
r1 = mvnrnd(mu,SIGMA,400);
mu = [9 3];
SIGMA = [10 0; 0 3];
r2 = mvnrnd(mu,SIGMA,400);
对两个满足二维正态分布的二维数组,如何从中分别随机选出N个数据.
对不起,我好像说的不太准确,应该是两个数组,每个数组中的元素是(x,y).麻烦各位了……
mu = [2 3];
SIGMA = [3 0; 0 3];
r1 = mvnrnd(mu,SIGMA,400);
mu = [9 3];
SIGMA = [10 0; 0 3];
r2 = mvnrnd(mu,SIGMA,400);
这里选择的关键函数是randperm函数,它是对n个整数的随机排列!
mu = [2 3];
SIGMA = [3 0; 0 3];
r1 = mvnrnd(mu,SIGMA,400);
mu = [9 3];
SIGMA = [10 0; 0 3];
r2 = mvnrnd(mu,SIGMA,400);
N=100;%选择的数目
K=randperm(400);
index=K(1:100);
plot(r1(index,1),r1(index,2),'r+');hold on;
plot(r2(index,1),r2(index,2),'+');
figure
plot(r1(index,1),r1(index,2),'+');
figure
plot(r2(index,1),r2(index,2),'+');
mu = [2 3];
SIGMA = [3 0; 0 3];
r1 = mvnrnd(mu,SIGMA,400);
mu = [9 3];
SIGMA = [10 0; 0 3];
r2 = mvnrnd(mu,SIGMA,400);
N=100;%选择的数目
K=randperm(400);
index=K(1:100);
plot(r1(index,1),r1(index,2),'r+');hold on;
plot(r2(index,1),r2(index,2),'+');
figure
plot(r1(index,1),r1(index,2),'+');
figure
plot(r2(index,1),r2(index,2),'+');