- Generate numbers with a small standard deviation to keep them close to the mean.
- Adjust the mean and standard deviation to fit within the desired range [8, 32].
- Ensure the values stay in the range [8, 32] by rounding and clamping.
skewness in random numbers
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am generating 30 random numbers ranging within 8 32 by
w1=randi([8 32],1,30);
Now I need a skewness in this randomly generated..i.e. the avg difference between the elements needs to be smaller,
like 8 8 9 10 10 11 12 13 13 14......like this way
If I could draw this distribution from a normal distribution then the std deviation that's I need to make smaller...
is there any way to do so?
0 comentarios
Respuestas (1)
Samayochita
el 24 de Feb. de 2025
Hi Tusu,
I understand that you want to generate random numbers between 8 and 32, but instead of the numbers being completely random, they should be closer together (less variation). You can control the spread of randomly generated numbers by drawing from a normal distribution using ‘randn’
You can follow the steps below to achieve this:
I have provided the sample code below, additionally you can sort the values before displaying them using ‘sort’
(https://www.mathworks.com/help/matlab/ref/double.sort.html) to ensure they are in ascending order (as shown in your example).
n = 30; % Number of random values
mu = 20; % Mean of the distribution (center of the range)
sigma = 3; % Small standard deviation for less spread
w1 = round(mu + sigma * randn(1, n)); % Generate numbers using normal distribution
% Clamp values within [8, 32]
w1(w1 < 8) = 8;
w1(w1 > 32) = 32;
% Optional -> sort in ascending order
w1 = sort(w1);
% Display the result
disp(w1);
I hope this works for you.
0 comentarios
Ver también
Categorías
Más información sobre Random Number Generation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!