Matlab Random Distribution Histogram

I am new to Matlab, and I have already looked for a whole bunch of different sites, but I did not find a solution (at least, understandable).

I have a 290x233 matrix with double values โ€‹โ€‹from 0.1 to 4.7. I want to generate a histogram from all the data in this matrix, so that there are strips for the range 0.5 โ†’ I want to see how many values โ€‹โ€‹exist in the range from 0 to 0.5, from 0.5 to 1 and so on ...

So far I have managed to have a strict plan. Using this code:

bins=[0.25:0.5:4.75]; n2=histc(a_dif_1, bins); bar(bins,n2,'hist'); 

I managed to get the result when there is a whole bunch of peaks in each box (see the figure below). This means that it shows me the presence of each individual value within the bin range.

enter image description here

then I found out about the "stacked" option and using

 bins=[0.25:0.5:4.75]; n2=histc(a_dif_1, bins); bar(bins,n2,0.8,'stacked','b'); 

Thus, at least I got big bars showing the total number of events within 1 bin (for this, 10 rectangular bars are shown, shown below).

enter image description here

Right now I'm wondering if bars showing the total number of values โ€‹โ€‹in the basket are the right thing to do? In addition, I noticed that my bars, which Iโ€™m getting, are leaving the center of the bunker (the bars on the right are not in the middle of two x-ticks) - did I mess up with the bunkers ??

As a bonus, I finally would like to draw a curve on top of the bars. The curve should show the following peaks that I described earlier, very generalized, so I can give more detailed information about the distribution of data separately from the bars.

Thanks for any help or ideas!

UPDATE

THANKS VERY MUCH for the tips. I changed histc to hist

 bins=[0.25:0.5:4.75]; hist(a_dif_1(:), bins) 

... and Matlab gives me exactly what I wanted:

enter image description here

+4
source share
1 answer
 a = 0.1; b = 4.7; r = a + (ba).*rand(290,233); bins=[0.25:0.5:4.75]; hist(r(:)) hist(r(:),bins) 

this is normal?

enter image description here

+1
source

Source: https://habr.com/ru/post/1445042/


All Articles