Using histogram() data without plotting or calculating the figure.

조회 수: 93 (최근 30일)
Thomas Houllier
Thomas Houllier 2016년 1월 9일
댓글: Erik Lindskog 2022년 10월 12일
Hi, this is my first post here.
I really need to optimize a function so as to make it as fast as possible. In it, I use the histogram function. All I need is the histogram().Values and histogram().BinEdges data. I don't need to plot anything and I need to keep the computation time to the bare minimum. The code I use is roughly:
fig=figure; set(fig,'visible','off');
H=histogram(...);
h=H.Values;
b=H.BinEdges;
% Some data treatment
%%%%
close(fig);
By doing 'tic-tocs' I found out that these precise lines were taking up 90% of the execution time. Is there any way to have access to the histogram data without opening a figure, or any other way of optimizing time ? I mean not opening a figure at all, not just hiding it, as I've already done that.
Thanks in advance !
  댓글 수: 1
Erik Lindskog
Erik Lindskog 2022년 10월 12일
Possibly a different way to compute a histogram without plotting a figure is to use the function histcounts to compute the histogram counts and edges. Later the histogram can then be plotted with the histogram function.
E.g.:
[counts, edges] = histcounts(data, 100) % Computes the histogram counts and edges for 'data' without plotting
...
histogram('BinEdges', edges, 'BinCounts', counts) % Plots a histogram with edges 'edges' and counts 'counts'.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2016년 1월 9일
If you only want the histogram values and not the plot, use the histcounts (or histc) functions.
  댓글 수: 5
Steven Lord
Steven Lord 2021년 3월 4일
The second output from histcounts contains the edges.
Amir Pasha Zamani
Amir Pasha Zamani 2021년 4월 2일
Thanks Star
I have the same problem with my codes efficiency
But even with histcount the code is still slow

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by