I want to generate the random vector containing the number from the user defined range. For example: numbers = [1 2 4 10] The random vector should always consist of these numbers. Eg. rand_num= [1 1 2 10 5 2 10] Thanks.
我想生成包含用户定义范围中的数字的随机向量。例如:numbers = [1 2 4 10]随机向量应始终由这些数字组成。例如。 rand_num = [1 1 2 10 5 2 10]谢谢。
1 个解决方案
#1
2
Let
让
numbers = [1 2 4 10]; %// population to sample from
N = 5; %// how many samples to take
You can use randsample
(Statistics Toolbox):
您可以使用randsample(统计工具箱):
rand_num = randsample(numbers, N, true); %// "true" means sample with replacement
or randi
(standard function):
或randi(标准功能):
rand_num = numbers(randi(numel(numbers), 1, N));
#1
2
Let
让
numbers = [1 2 4 10]; %// population to sample from
N = 5; %// how many samples to take
You can use randsample
(Statistics Toolbox):
您可以使用randsample(统计工具箱):
rand_num = randsample(numbers, N, true); %// "true" means sample with replacement
or randi
(standard function):
或randi(标准功能):
rand_num = numbers(randi(numel(numbers), 1, N));