我試圖計算兩個值之間的差異,我從一個結構數組上的每個條目得到某個參數('年齡')。計算色散C
我有一個輔助.txt文件,並且這個整點是要經過的每個.txt文件的單獨的線(每行是一個字符串)。它的更好,如果我狀態的例子,所以,在這裏我們去:
matrix[n][n]:
1 2 3 4
1 2 3
1 2
因此,結構看起來有點像這樣:
struct person {
int id; //where im comparing between the matrix and the structure;
int age; //what I need to calculate the dispersion
}
我要比較的每一行的每個值.txt,如果它與結構中的任何id相匹配,我就得到它的年齡。現在來了棘手的部分。
要計算我需要得到以下工作爲我分散:
讓我們爲例.txt文件的第一行:分散將是:
讓我們說,「年齡'= id(n)的年齡;
//in this case nGroups = 6 (number of age(n)-age(m) operations)
dispersion(first_row)= [ [|age(1)-age(2)|] + [|age(1)-age(3)|] + [|age(1)-age(4)|] + [|age(2)-age(3)|] + [|age(2)-age(4)|] + [|age(3)-age(4)|] ]/nGroups
所以我必須爲矩陣的每一行做這個。我試過了,並且管理了下面的代碼,但是在'數學'部分,我的大腦凍結了一下。
// going through each line of the matrix
for(i=0; i<nconjuntos; i++) {
// going through each column of the matrix
for(j=0; j<strlen(aux[i]); j++) {
// going through all the structures in the structure array
for(k=0; k<TOTAL; k++) {
// comparing each number with it's id equivalent in
// each structure.id parameter in the array
if(aux[i][j] - 48 == pessoas[k].id) {
}
}
}
}
任何幫助我可以在我的代碼中前進的幫助將非常感激!
呵呵。我不知道[散佈](http://en.wikipedia.org/wiki/Statistical_dispersion)是一個統計術語。 –