lognormal
lognormal: creates lognormal distribution with desired mode (peak-value)
usage: lognormal(mode_log,sigma_n,n,plotit)
--- INPUT arguments:
'mode_log' ---> can be any positive value (is the most frequent value of the lognormal distribution -> the peak in the histogram)
'sigma_n' ---> standard deviation of the corresponding normal distribution
--> CAUTION: it is not the standard deviation of the lognormal distribution, because it is a somewhat unuseful value for an asymmetric distribution
'n' ---> number of n-values the distribution should have
'plotit' ---> plot switch (0=no,1=yes)
How it works:
1.) calculate the mean(normal) from the input mode_log (lognormal) and sigma_n (normal) with mu_n = log(mode_log) + sig_n^2
2.) create random normal distrubution r with n-values
3.) shift and transform the normal distribution with dist_n = mu_n + sig_n * r
4.) transform the normal distribution to lognormal with dist_log = exp(dist_n)
5.) calculate the output mode of the lognormal distribution with mode_out = exp(mean(dist_n)-std(dist_n)^2)
--- OUTPUT arguments:
'output' struct with several fields:
'dist_n' ---> created normal distribution
'mu_n_in' ---> input mean value for the normal distribution calculated from input 'mode_log' and 'sigma'
'mu_n_out' ---> output mean value of the normal distribution
'sig_n_in' ---> input standard deviation ('sigma') of the normal distribution
'sig_n_out' ---> output standard deviation of the normal distribution
'dist_log' ---> created lognormal distribution
'mode_log_in' ---> input mode of the lognormal distribution
'mode_log_out' ---> output mode of the lognormal distribution calculated from mean and standard deviation of the normal distribution 'dist_n'
'mu_log' ---> output mean value of the lognormal distribution
'sig_log' ---> output standard deviation of the lognormal distribution
--- Example usage:
output = lognormal(1-e4,1,1e5,1)
- will create a lognormal distribution with mode 0.0001
- the corresponding normal distribution will have a standard deviation of 1
- 10'000 values will be created
- both distributions will be plotted
Cite As
Walther (2026). lognormal (https://www.mathworks.com/matlabcentral/fileexchange/29407-lognormal), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- AI and Statistics > Statistics and Machine Learning Toolbox > Probability Distributions and Hypothesis Tests > Continuous Distributions > Lognormal Distribution >
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
