Random number generate in an interval
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Guilherme Lopes de Campos
 el 14 de Sept. de 2023
  
    
    
    
    
    Comentada: Walter Roberson
      
      
 el 22 de Sept. de 2023
            Hi community, 
I would like to generate random number in the follow distribuition: Normal, Gamma and Weibull. 
Amount of data required: 5000 numbers at interval [a,b]
At the example, it was used the follow code: 
A = linspace(0,1,5000)
sr = size(A)
b = normrnd(27.5,15.73,sr)
plot(b)
Its works, however, the valid interval to generate was [1,54] 
Can us help me, please? 
Yours faithfully
7 comentarios
  Walter Roberson
      
      
 el 14 de Sept. de 2023
				Right, different interpretations of what "clipping" means in the context.
format long g
b = normrnd(27.5,15.73,[1 500000]);
out_of_range = (b < 1) | (b > 54);
mean(out_of_range) * 100
so over 9% of the samples are outside of the target range
  Walter Roberson
      
      
 el 22 de Sept. de 2023
				It works!  Thank you very much 
Respuestas (2)
  the cyclist
      
      
 el 14 de Sept. de 2023
        
      Editada: the cyclist
      
      
 el 14 de Sept. de 2023
  
      A normal distribution, by definition, has support from negative infinity to positive infinity. You cannot have both a normal distribution and a finite range.
You can use the truncate function to create a truncated normal distribution object, and draw values from that. (See the second example on that page.) Is that what you want?
0 comentarios
  Bruno Luong
      
      
 el 14 de Sept. de 2023
        
      Editada: Bruno Luong
      
      
 el 15 de Sept. de 2023
  
      The file TruncatedGaussian.m is from this page https://www.mathworks.com/matlabcentral/fileexchange/23832-truncated-gaussian?s_tid=srchtitle 
This doesn't need stat toolbox.
sigma = 15.73;
mu = 27.5;
interval = [1 54];
n = [1, 5000000];
X = TruncatedGaussian(-sigma,interval-mu,n) + mu;
histogram(X)
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!










