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

c0vxltue  于 11个月前  发布在  Matlab
关注(0)|答案(3)|浏览(102)

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

x33g5p2x

x33g5p2x1#

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]

daolsyd0

daolsyd02#

[Y,X] = max(h);

字符串
你试过这个吗?

y3bcpkx1

y3bcpkx13#

找到直方图中的最高峰

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}')

字符串

相关问题