2016-11-26 25 views
1

我想知道我的數據集中的哪些元素進入了二元直方圖中最高的區域,並且沒有找到有關如何在線執行此操作的信息。我懷疑這是可能的,因爲它非常有用。瞭解數據集中的哪些元素在直方圖中進入最高區域? MATLAB

我知道我可以做一些其他的代碼,幫助我找到它,但我想知道是否有一個簡潔的方式來做到這一點。例如,我可以用一個條件來搜索數據集,這有助於我提取掉落入容器中的東西,但我對此不感興趣。現在我寫了

X = [Eavg,Estdev]; 
hist3(X,[15 15]) 

結果是一個15x15 bin二元直方圖。我想以非常簡潔的方式提取最高檔中的元素。

我做了統計力學(蒙特卡洛)模擬,如果值得一提...

+0

查看['discretize'](https://www.mathworks.com/help/matlab/ref/discretize.html)函數。 –

回答

1

簽名[N, CEN] = hist3(...返回bincounts和垃圾箱的中心。倉中心可以轉換爲倉邊。然後可以使用邊來找出哪些數據元素落入特定的箱中。

X = randi([1 100],10,2); 
[N, CEN] = hist3(X,[5 5]); 
%find row and column of highest value of histogram 
%since there may be multiple histogram values that 
%are equal to maximum value then we select the first one 
[r,c]= find(N==max(N(:)),1); 
%convert cell of bin centers to vector 
R = [CEN{1}]; 
C = [CEN{2}]; 
%convert bin centers to edges 
%realmax used to include values that 
%are beyond the first and the last computed edges 
ER = [-realmax R(1:end-1)+diff(R)/2 realmax]; 
EC = [-realmax C(1:end-1)+diff(C)/2 realmax]; 
%logical indices of rows where data fall into specified bin 
IDX = X(:,1)>= ER(r) & X(:,1)< ER(r+1) & X(:,2)>= EC(c) & X(:,2)< EC(c+1) 
+0

不錯!我可能需要研究一下,但似乎完美地工作。 – DLV