Importing histogram count and bin values into a matlab histogram object

2 Ansichten (letzte 30 Tage)
Hello,
I have a two vectors that describe a histogram.
I'd like to import those into a Matlab histogram object so that I can change parameters more easily.
For instance, this is basically what I have:
Center bin values:
BinValues = [-4 -3 -2 -1 0 1 2 3 4 ];
and count values per bin
CountValues = [7 8 2 6 0 3 4 6 1];
This is simplified of course, but in the future I might want to do something like reduce the number of bins from 9 to 5.
How do I create a matlab histogram object given what I have?
  1 Kommentar
Tom Mozdzen
Tom Mozdzen am 22 Dez. 2020
If I try this:
h=histogram('BinEdges',[-10.5:10.5] , 'BinCounts', CountValues);
then it puts me into manual mode and won't do rebinning for me.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 23 Dez. 2020
Pretty sure you can't. From the documention for histogram
histogram('BinEdges',edges,'BinCounts',counts) manually specifies bin edges and associated bin counts. histogram plots the specified bin counts and does not do any data binning.
From the last sentence, you can see that creating a histogram this way does not include the underlying data. Just the counts. To me that means rebinning is not possible from the edges and counts data.
  4 Kommentare
Tom Mozdzen
Tom Mozdzen am 23 Dez. 2020
I'm analyzing timestamps from a single photon detector. I populate the bins as I go. In 1 second of data collection, I have nearly 25 million timestamps. My file is huge as it runs for about an hour. So I'd have around 20x10^9 items in my data file if I saved each data point. )-:
As it is, my native histogram bins range from -400000 to +400000 in steps of 1 (these are picoseconds), so 800001 total bins with 1000s of stampstamps registering in each bin.
I'd like to be able to condense to bins of 25 ps 50 ps, 250 ps. In the past, I would write a for/next loop. But that is a pain and this problem comes up now and then, and I was hoping there were more sophisticated histogram objects or functions that could do this for me.
Cris LaPierre
Cris LaPierre am 23 Dez. 2020
If it's still open, you can update a property and it redraws the histogram. Making the bins wider does not reduce the data saved in the object, though. It just changes the appearance.
x = randn(10000,1);
h = histogram(x);
% the original has bins ever 0.2. Modify to have width of 2.
% the displayed histogram now uses the new edges.
h.BinEdges = [-4:2:4];

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Steven Lord
Steven Lord am 23 Dez. 2020
I'm analyzing timestamps from a single photon detector. I populate the bins as I go. In 1 second of data collection, I have nearly 25 million timestamps. My file is huge as it runs for about an hour. So I'd have around 20x10^9 items in my data file if I saved each data point. )-:
That sounds like it could be Big Data. Can you store the data as a tall array backed by a datastore array, perhaps a tabularTextDatastore or a spreadsheetDatastore? You can create a histogram using that tall array. See this documentation page for more information.
  1 Kommentar
Tom Mozdzen
Tom Mozdzen am 23 Dez. 2020
Thanks for the recommendation on datastore array.
It looks like the simplest solution for me is to just write a function to rebin my bins into fewer bins by summing the counts in the old bins.

Melden Sie sich an, um zu kommentieren.

Tags

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by