Switching from hist to histogram

50 Ansichten (letzte 30 Tage)
Louise Wilson
Louise Wilson am 10 Nov. 2025 um 1:47
Kommentiert: dpb vor etwa 7 Stunden
I am trying to make my code more robust by switching from use of histogram to hist.
Currently, I use hist as follows:
hist(psd,vec)
where psd is a matrix and vec is a vector.
The output of hist is a matrix where the height is the length of the vec data, and the width is the width of the psd data.
It gives me the values in psd, in bins with bin centres? listed by vec.
The output of histogram is instead an object, and I'm not sure how to derive the info I need from this object? Thanks

Akzeptierte Antwort

dpb
dpb am 10 Nov. 2025 um 14:33
Bearbeitet: dpb am 10 Nov. 2025 um 18:36
The changes in behavior relative to venerable hist introduced by histogram are a pain, agreed. That there isn't an option to specify bin centers instead of only edges is an egregious omission. While one can convert the centers to edges, it's just another piece of minutiae to deal with instead of solving the underlying problem. At least they ought to have packaged a conversion function that implements the conversion outlined at <Convert Bin Centers to Edges>.
As for your usage, "if it ain't broke, don't fix it!" would be my recommendation. While deprecated for new code, there's no chance Mathworks can remove hist entirely and while it might be somewhat advantageous for new code to use the newer function, there really isn't any strong reason to work over current code unless there were some real advantage to the object that is presently difficult later on in your code besides just the shown code snippet usage.
$0.02, im(ns)ho, ymmv, etc., etc., ...
  5 Kommentare
Paul
Paul vor etwa 19 Stunden
I've really come to appreciate the normalization property of the histogram object.
dpb
dpb vor etwa 5 Stunden
It's not so much the packaging as that they didn't provide a painless path to be able to reproduce prior behavior. I do find having to only set edges a nuisance as the typical use I have really is based on desired bin centers instead. I haven't yet taken the time to build a generic translation function.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Produkte


Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by