Hi i want to know if i have a specific numbers like (5 9 11) and i want to distribute them randomly on array which i know it's size , How can i do that?

Hi i want to know if i have a specific numbers like (5 9 11) and i want to distribute them randomly on array which i know it's size , How can i do that?

답변 (2개)

If you have the Statistics Toolbox then randsample()
Otherwise:
specific_numbers = [5, 9, 11];
array_size = [48,93]; %for example
rand_array = specific_numbers( randi(length(specific_numbers), array_size) );
This presumes equal probability for the samples.

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

제품

태그

질문:

2015년 12월 14일

댓글:

2015년 12월 14일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by