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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Let
numbers = [1 2 4 10]; %// population to sample from
N = 5; %// how many samples to take
You can use randsample
(Statistics Toolbox):
rand_num = randsample(numbers, N, true); %// "true" means sample with replacement
or randi
(standard function):
rand_num = numbers(randi(numel(numbers), 1, N));