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

9 ビュー (過去 30 日間)
Jaime De La Mota Sanchis
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 日
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 件のコメント
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 件)

カテゴリ

Find more on Data Distribution Plots in Help Center and File Exchange

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by