2013-06-30 49 views
-2

我需要一個help.i使用使用hist命令的matlab代碼,我需要Java等效代碼或matlab中的hist函數背後的邏輯,以便我可以在java中編寫代碼或c。提前感謝。在matlab中需要代碼或邏輯在hist命令後面

+0

你可以嘗試'編輯hist'並查看matlab實現hist的方法。 – bla

+0

有各種選項 - 它可以表現的不同方式(返回值,創建箱,繪圖,多個數據集,註釋...)。如果你簡化了你的問題會很有幫助 - 例如,「如何創建一個C數組,其中包含一系列對應於數組X(50,1)的箱子,但事先並不知道需要多少個箱子,但是箱子必須是'10'寬且均勻間隔的「。我們可以提供幫助 - 但對於一般情況,您可以遵循@ natan的建議(但我甚至不確定這會有所幫助 - 這是一個非常複雜的功能,有很多選項)。 – Floris

回答

1

爲直方圖化(假設你已經已知的恆定寬度的幀,並且不需要的最有效的代碼可能的)簡單的邏輯:

float x[50]; // assumed to be array of data values 
float binWidth, firstBin; // bins of width binWidth; first one centered on firstBin 
int numBins; // number of bins 
int *bins, tooSmall = 0, tooLarge = 0, ii, indx; 

bins = (int*)calloc(numBins * sizeof(int)); // allocate, set to zero 

for(ii = 0; ii < 50; ii++) { 
    indx = floor((x[ii]-firstBin)/binWidth + 0.5); 
    if (index < 0) { 
    tooSmall++; 
    } 
    elseif (index >= numBins) { 
     tooLarge++; 
    } 
    else { 
     bins[indx]++; 
    } 
    } 
} 

在最後你有數據的直方圖在x ,兩個計數器對應的數據不符合該範圍(在或超出範圍)。

免責聲明:未經編譯器書面進行測試。看起來「關於正確」 - 在依賴它之前在已知案例上對其進行測試。