How to get 10000 variable numbers between the range of 0 and 100?

2 次查看(过去 30 天)
i want a variable array of 10000 numbers from 0 to 100.
a = -5; b = 5; varx = a + (b-a).*rand(10000,1); varX = 10.^varx;
so i want this in the above format.
can you help me out?
  4 个评论

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2022-8-27
编辑:Star Strider 2022-8-28
If you want the numers to be between and , use the logspace function, then use randperm to randomise them —
varx = logspace(-5, 5, 1E+5) % Generate Vector
varx = 1×100000
1.0e+05 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
varx = varx(randperm(numel(varx))) % Randomize It
varx = 1×100000
1.0e+05 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0000 0.0000 0.0000 0.0241 0.0000 0.0002 0.0000 0.9879 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0282 0.0000 0.0000 0.0000 0.0014 0.1385 0.0000 0.0000 0.0000
Check = [min(varx) max(varx)] % Check Result
Check = 1×2
1.0e+05 * 0.0000 1.0000
log10Check = log10(Check) % Verify
log10Check = 1×2
-5 5
EDIT — (28 Aug 2022 at 2:16)
actually i want the values between 10^(-5) and 10^2.’
varx = logspace(-5, 2, 1E+5) % Generate Vector
varx = 1×100000
1.0e+00 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
varx = varx(randperm(numel(varx))) % Randomize It
varx = 1×100000
12.2648 28.3893 0.0239 0.0008 4.9518 2.1702 0.0146 0.8131 0.2272 0.0000 0.2467 0.4178 5.3700 9.1466 28.9484 53.1701 0.0206 0.0001 0.0094 0.0249 2.5477 41.2094 1.6019 0.3318 41.3358 0.0008 66.8018 0.0000 0.7349 18.7881
Check = [min(varx) max(varx)] % Check Result
Check = 1×2
0.0000 100.0000
log10Check = log10(Check) % Verify
log10Check = 1×2
-5 2
.

更多回答(1 个)

Abderrahim. B
Abderrahim. B 2022-8-27
移动:Image Analyst 2022-8-27
Try this --
varx = 100*rand(10000, 1) ;
min(varx)
ans = 0.0227
max(varx)
ans = 99.9844

类别

Help CenterFile Exchange 中查找有关 Elementary Math 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by