Histogram from numberdensity values.

Dear All,
I have a data of x and y, where x is the radius of the particles and y denotes the number density of particles that has radius in x. Now I would like to make a histogram, could you kindly help me with it.
Sample Data:
x = [6 5 3 23 67 33 74]
y = [5 8 2 4 9 2 1] *1e24
Thanks in advance

2 Comments

Torsten
Torsten on 6 Jan 2023
Edited: Torsten on 6 Jan 2023
Why does the 3 appear two times in x with different associated number densities ?
That was a mistake, it is supposed to be
x = [6 5 3 23 67 33 74]
y = [5 8 2 4 9 2 1] *1e24

Sign in to comment.

Answers (2)

Is this bar graph what you need? If not, can you explain a bit more?
x = [6 5 3 23 67 33 74];
y = [5 8 2 4 9 2 1] *1e24;
bar(x,y)
That already is a histogram. It's just badly named. x is the histogram bin value (represents radius), and y is the histogram count value (representing what you call "density" but is the number of data points with the associated x (radius) value. You can plot this histogram simply with the bar function.
x = [6 5 3 23 67 33 74];
y = [5 8 2 4 9 2 1] *1e24;
bar(x, y);
xlabel('radius')
ylabel('Count')
title('Histogram of Radii')
grid on;
The histogram function is not needed because your x and y are already a histogram. You don't need to "make a histogram" because you already have it. If you want to normalize it by dividing by the tallest value, or the sum of all values, you could of course do that.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:

Products

Release

R2022a

Community Treasure Hunt

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

Start Hunting!