Matlab 制作2个不同的样本阵列(无重复阵列元素)

Matlab 制作2个不同的样本阵列(无重复阵列元素),matlab,Matlab,我正在尝试制作两个不同的样本阵列,我知道如何制作这样的样本: x_1 = randsample(1:10,5,true); x_2 = randsample(1:10,5,true); 但是我希望x_2是一个不同的样本,我的意思是在另一个x_1数组中不重复该数组的任何元素。Matlab中有没有简单的函数可以做到这一点,而不必测试每个元素并手动更改它 感谢您的帮助最简单的方法是从分布中抽取两倍的样本,然后将结果分成两部分。然后保证在数组内或数组之间没有重复的值 % Sample 10 times

我正在尝试制作两个不同的样本阵列,我知道如何制作这样的样本:

x_1 = randsample(1:10,5,true);
x_2 = randsample(1:10,5,true);
但是我希望
x_2
是一个不同的样本,我的意思是在另一个
x_1
数组中不重复该数组的任何元素。Matlab中有没有简单的函数可以做到这一点,而不必测试每个元素并手动更改它


感谢您的帮助

最简单的方法是从分布中抽取两倍的样本,然后将结果分成两部分。然后保证在数组内或数组之间没有重复的值

% Sample 10 times instead of 5 (5 for each output)
samples = randsample(1:10, 10);

%     2    10     4     5     3     8     7     1     6     9

% Put half of these samples in x1
x1 = samples(1:5);

%     2    10     4     5     3


% And the other half in x2
x2 = samples(6:end);

%     8     7     1     6     9
如果希望在阵列中允许重复,可以使用另一种方法。然后,通过删除第一个调用中出现的任何内容,将输入示例修改为第二个
randsample
调用

% Define the initial pool of samples to draw from
samples = 1:10;

x1 = randsample(samples, 5, true);

%     5     4     8     8     2

% Remove things in x1 from samples
samples = samples(~ismember(samples, x1));

x2 = randsample(samples, 5, true);

%     6     6     7     9     9

最简单的方法是从分布中抽取两倍的样本,然后将结果分成两部分。然后保证在数组内或数组之间没有重复的值

% Sample 10 times instead of 5 (5 for each output)
samples = randsample(1:10, 10);

%     2    10     4     5     3     8     7     1     6     9

% Put half of these samples in x1
x1 = samples(1:5);

%     2    10     4     5     3


% And the other half in x2
x2 = samples(6:end);

%     8     7     1     6     9
如果希望在阵列中允许重复,可以使用另一种方法。然后,通过删除第一个调用中出现的任何内容,将输入示例修改为第二个
randsample
调用

% Define the initial pool of samples to draw from
samples = 1:10;

x1 = randsample(samples, 5, true);

%     5     4     8     8     2

% Remove things in x1 from samples
samples = samples(~ismember(samples, x1));

x2 = randsample(samples, 5, true);

%     6     6     7     9     9