How to find the maximum of a normalized fit of a histogram

9 Ansichten (letzte 30 Tage)
Sumara
Sumara am 30 Okt. 2019
Beantwortet: Jeff Miller am 7 Nov. 2019
I'd like to find, point, and label the maximum of a normalized fit curve on a histogram
The code I'm using to build the histogram/fit curve is:
Average_Insert_Time = mean(All_Data); %Find average of data for random codon to mark on histogram
Histogram = histfit(All_Data,5000,'normal');
hold on
xlim([0 (Average_Insert_Time*2)]);%places average at center of graph
line([Average_Insert_Time, Average_Insert_Time], ylim, 'LineWidth', 2, 'Color', 'g'); %add average vertical
hold off
It produces a figure that looks like this:
I want to place a marker on the maximum value of this normalized distribution, which then denotes the Y-value

Antworten (2)

Dheeraj Singh
Dheeraj Singh am 6 Nov. 2019
You can use histcountsto find the frequency of each bin.
N=histcounts(All_Data,200);
Then use max to find the max value and the bin index using max:
[val,idx]=max(N);
Then simply use plot to plot the marker:
plot(idx,val,'r*') ;
  1 Kommentar
Sumara
Sumara am 6 Nov. 2019
This would give me the max of the histogram instead of the max of the normalization curve, no?

Melden Sie sich an, um zu kommentieren.


Jeff Miller
Jeff Miller am 7 Nov. 2019
Try this:
dist = Histogram(2)
maxnorm = max(dist.YData);
line([min(dist.XData) max(dist.XData)], [maxnorm maxnorm], 'LineWidth', 2, 'Color', 'g');

Community Treasure Hunt

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

Start Hunting!

Translated by