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

时间:2019-05-17 14:43:58

标签: matlab histogram matlab-figure

如何将直方图中最高峰的x值保存为变量?谢谢 enter image description here

2 个答案:

答案 0 :(得分: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] 

答案 1 :(得分:0)

[Y,X] = max(h);

您尝试过吗?