Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Average of a matrix 1

Status
Not open for further replies.

hill007

Technical User
Mar 9, 2004
60
US
Hi friends,

I need a help to determine an average of a large matrix, which has 328 rows and 368 columns.
I am including an example as what I achieve to do:

Example matrix (3 by 4):

3 4 8 9
1 6 9 6
2 3 4 8

The average of first column (3, 1, and 2)is: 2
The average of second column (4,6,3) is: 4.33
The average of 3rd column (8,9,4) is: 7
The average of 4th column (9,6,8) is: 7.67

Thus, the total average (2+4.33+7+7.67) = 5.25

I am looking for a final average value from the matrix.

Any help is appreciated.

 
Code:
{
  for(i=1; i <= NF; i++)
     sum[i] += $i

  nf=NF
}
END {
  for(i=1; i <= nf; i++) {
    avg = sum[i]/FNR; avgT += avg
    printf("The average of %d column: %.2f\n", i, avg)
  }

  printf("\nTotal average: %.2f\n", avgT/nf)
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top