Importing histogram count and bin values into a matlab histogram object

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 comentario

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.

Iniciar sesión para comentar.

 Respuesta aceptada

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 comentarios

I agree that it wont work using that method.
Is there a method that will work?
Is there a reason you won't have access to the data?
Take a look at the properties you can access from the histogram object. Depending on how you created the histogram, Data is part of the object. You can use that to create another histogram.
x = randn(10000,1);
h = histogram(x);
% Use the data to create a new histogram with 10 bins
figure
histogram(h.Data,10)
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.
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];

Iniciar sesión para comentar.

Más respuestas (1)

Steven Lord
Steven Lord el 23 de Dic. de 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 comentario

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.

Iniciar sesión para comentar.

Productos

Versión

R2020a

Etiquetas

Preguntada:

el 21 de Dic. de 2020

Comentada:

el 23 de Dic. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by