How can I plot points on top of a histogram's bins?

조회 수: 19 (최근 30일)
Jaime De La Mota Sanchis
Jaime De La Mota Sanchis 2022년 9월 16일
댓글: Jaime De La Mota Sanchis 2022년 9월 16일
Hello everyone.
I currently hace the following code
figure
plot(EvaluesJ, 0,'r*', 'MarkerSize', 10)
hold on
histogram(rand_num)
and I want to change the points in which EvaluesJ are plotted, isntead of zero, I want them to be on top of the bin of the histogram of rand_num, however, I don't know how to do this.
Can anyone please help me?
Best regards.
Jaime.
  댓글 수: 2
Jaime De La Mota Sanchis
Jaime De La Mota Sanchis 2022년 9월 16일
Don't worry, I expected as much, I was trtiying to reproduce the figure 2 of this paper. I will tel my director that it cannot be done. Thanks anyway.
Jaime.
Jaime De La Mota Sanchis
Jaime De La Mota Sanchis 2022년 9월 16일
I don't think posting my whole code can help anyway, the random numbers and the points are already in the samples I have posted

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

채택된 답변

Adam Danz
Adam Danz 2022년 9월 16일
I think this is close to what you're looking for and will get you most of the way there.
h = histogram(rand(1,5000)*100);
% Compute centers of hist bins
binCnt = h.BinEdges(2:end) - h.BinWidth/2;
% Get bar heights
barHeights = h.Values;
% plot red * at top of bins
hold on
plot(binCnt, barHeights, 'r*')
  댓글 수: 3
Adam Danz
Adam Danz 2022년 9월 16일
편집: Adam Danz 2022년 9월 16일
My answer gets you most of the way there. The only problem that needs solved is identifying which bins the evalues_J values fall in which should be easy.
rng('default')
pd = makedist('Exponential', 3);
t = truncate(pd,0,5);
rand_num=random(t, 100000, 1);
h = histogram(rand_num);
evalues_J=[0.2049,1.0270,2.3133,3.7086,4.7306]; % row vector!
% Find bin index for each point
logIdx = h.BinEdges(1:end-1)' <= evalues_J(:)' & h.BinEdges(2:end)' > evalues_J(:)';
[binID,~] = find(logIdx);
% plot points
hold on
plot(evalues_J, h.Values(binID), 'r*')
% Plot them at the bottom too for verification
plot(evalues_J, 0,'k*')
Jaime De La Mota Sanchis
Jaime De La Mota Sanchis 2022년 9월 16일
Thank you very much, this is just what I need.
Best regards.
Jaime.

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by