How can I generate random number between 1 and 10, and at the same time I want to exclude number 3 & 6?

18 次查看(过去 30 天)
How can I generate random number between 1 and 10, and at the same time I want to exclude number 3 & 6 using M-file?
  3 个评论
Mohd Helmi Mansor
Mohd Helmi Mansor 2019-3-21
I want to have one single number from the randomization process (Between 1 & 10). But the number must not be 3 & 6. So it can be either 1,2,4,5,7,8,9 or 10.

请先登录,再进行评论。

采纳的回答

Thorsten
Thorsten 2019-3-21
x = setdiff(1:10, [3, 6]);
r = x(randi(numel(x)));

更多回答(0 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by