如何找到直方图中最高峰的x值?

问题描述 投票:0回答:3

如何将直方图中最高峰的x值保存到变量中?谢谢

matlab histogram matlab-figure
3个回答
2
投票
fileID = fopen('q65.txt','r');
formatSpec = '%f';
file = fscanf(fileID,formatSpec);

h = histogram(file,50);
%Find index of maximum
[~, index]= max(h.Values);

delta = h.BinLimits(2)-h.BinLimits(1);
% find the range for a single bin
slot = delta./h.NumBins;

%location = minimum y + (index of maxmium)*slot 
lb = h.BinLimits(1) + (index-1)*slot;
ub = h.BinLimits(1) + (index)*slot;

location = [lb, ub]

位置是一个范围,不是固定数字

一个简单的

fileID = fopen('q65.txt','r');
formatSpec = '%f';
file = fscanf(fileID,formatSpec);
h = histogram(file,50);
%Find index of maximum
[~, index]= max(h.Values);
lb = h.BinEdges(index);
ub = h.BinEdges(index+1);
location = [lb, ub] 

0
投票
[Y,X] = max(h);

你尝试过这个吗?


0
投票

找到直方图中的最高峰

import numpy as np
x = np.array([1.2, 2.1, 3.0, 4.1, 4.2, 4.5, 4.9, 5.3])
hist, bin_edges = np.histogram(x, bins=7, range=[0, 7])
max_hist = max(hist)
max_hist_idx = np.where(hist == max_hist)[0][0]
max_hist_mean = (bin_edges[max_hist_idx] + bin_edges[max_hist_idx + 1]) / 2
print(f'Maximum value= {max_hist_mean:.1f}')
© www.soinside.com 2019 - 2024. All rights reserved.