Generating a histogram from lognormally distributed data

3 views (last 30 days)
Good Afternoon,
I am trying to modify the following script
mu = 0.015; % mean particle size
sg = 1.6; % standard deviation
Ntot = 1000; % total number concentration of particles
nbins = 50; % number of bins
data = lognrnd(mu,sg,[Ntot,1]); % generate data
h = histogram(data,nbins); % display data as histogram
Nconcs = h.Values; % determine number concentration
rMin = min(data); % find the minimum particle radius in the distribution
rMax = max(data); % find the maximum particle radius in the distribution
rs = linspace(rMin,rMax,nbins); % create vector containing particle radii
scatter(rs,Nconcs); % plot data
I would like to be able to provide the values for minumum and maximum particle radius but receive a similar output. The trouble I am having is I cannot figure out a way of generating the random data between these values. Because the data does not have to be random I have also tried using lognpdf and providing the values...
mu = 0;
sg = 1;
rs = linspace(0.05:0.01:1.25); % range of particle radii
data = lognpdf(rs,mu,sg); % lognormal pdf
...after which I am finding myself getting stuck. Below I shall state what Inputs I have and the Outputs I am trying to acheive.
Inputs:
  • mu and sg: the mean particle size and the standard deviation
  • rMin and rMax: the minimum and maximum particle size
  • Ntot: the total number concentration of particles
Outputs:
  • rs: a vector containing particle radii (ideally lognormally spaced)
  • Nconcs: a vector containing the approximate number concentration of each particle size corresponding to each element in rs
  • figure(1) : a plot with rs on the x axis and Nconcs on the y axis (ideally with a lognormally spaced x-axis)
  • figure(2): a histogram seperating radii into 50 bins of equal width showing the number concentration within each bin
I hope someone can help and i'm not missing anything too simple!!!

Answers (1)

Jeff Miller
Jeff Miller on 23 Feb 2021
What about something like this:
mu = 0.015; % mean particle size
sg = 1.6; % standard deviation
Ntot = 1000; % total number concentration of particles
nbins = 50; % number of bins
data = lognrnd(mu,sg,[Ntot,1]); % generate data
% only keep data from the range you want:
inRange = (data >= rMin) & (data <= rMax);
data = data(inRange);
h = histogram(data,nbins); % display data as histogram
Nconcs = h.Values; % determine number concentration
rMin = min(data); % find the minimum particle radius in the distribution
rMax = max(data); % find the maximum particle radius in the distribution
rs = linspace(rMin,rMax,nbins); % create vector containing particle radii
scatter(rs,Nconcs); % plot data
  6 Comments
Liam Holbeche-Smith
Liam Holbeche-Smith on 25 Feb 2021
I thought it best to provide some further background on what I am trying to acheive as I feel my explanations aren't very clear. I am trying to represent an aerosol population as described in the document below:
Available to me are the parameters Ntot, mu and sigma. I also have the lower and upper limits of r, which are rMin and rMax.
% code attempt for the first formula
pdf = Ntot/((sqrt(2*pi)*log(sigma))*exp(-(log(rs./mu).^2)./(2*log(sigma^2)));
I am not too sure how to go about the discrete approximation. The goal is to get two vectors containing the number concentraion and size at the mean value in each bin so I can create a plot similar to this one:
Hopefully this helps explain things a bit better.
Thanks again!!!
Jeff Miller
Jeff Miller on 25 Feb 2021
Sorry I am not being helpful. I 'm not sure I understand this background and have nothing to add to my previous suggestion.
BTW, your code attempt for pdf does not look like a legal pdf to me, because I think it will integrate to Ntot, whereas pdfs should integrate to 1.

Sign in to comment.

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!