Switching from hist to histogram
조회 수: 50 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
dpb
2025년 11월 10일 14:33
편집: dpb
2025년 11월 10일 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
dpb
대략 5시간 전
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!