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

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 Commenti

a=randi([0,100],[1,10000])
or,
a = -5 + (5+5)*rand(1,10000)
Note that because of:
varX = 10.^varx;
and the set limits, ‘varx’ will be between and . Is that what you want?
actually i want the values between 10^(-5) and 10^2.

Accedi per commentare.

 Risposta accettata

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
.

Più risposte (1)

Try this --
varx = 100*rand(10000, 1) ;
min(varx)
ans = 0.0227
max(varx)
ans = 99.9844

Categorie

Scopri di più su Random Number Generation in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by