# Can't define average for my matrix

I have a list defined as MarsDisk which, in MatrixForm, has 17 rows and 3 columns, which hold information about a photon energy level, photon flux, and uncertainty in the flux. I'm interested in taking the average of the energy levels and executed the following:

Average[MarsDisk[[i, 2]]]


and I received this error message:

Part::partw: Part 18 of {{0.8725,0.5,0.5},{0.817,0.4,0.4},[continues with the rest of my data points]} does not exist. >>

I don't get why this doesn't work because I never asked for the 18th element.

Then, I tried to create a For loop instead:

ψ = Array[c, {17, 2}];

For [i = 1, i <= 17, i++,

ψ[[i, 1]] = Avg[MarsDisk[[i, 1]]];

ψ[[i, 2]] = Avg[MarsDisk[[i, 2]]]]


which gave no error message but when I executed ψ it printed all elements as {Avg[0.8725], Avg[0.5]}, etc. So neither way worked.

Can anyone show me a way to successfully quantify the averages for each column of information in my matrix?

• I should add that I changed "Avg" to "Average" and the same exact issue came up – Amelia Henkel Aug 11 '16 at 16:40
• why don't you use 'All' instead of defining a loop? can you give an example of your matrix? for example use Average[a[[All,2]]] – Siav Josep Aug 11 '16 at 16:43
• I'm an amateur with this stuff and didn't know about using All. I tried Average[MarsDisk[[All,2]]] and it worked out just fine!! Thank you so much! – Amelia Henkel Aug 11 '16 at 16:47
• I'm glad that I helped :) Also if you use the 'Mean' function it gives the average of each column of your matrix. – Siav Josep Aug 11 '16 at 16:49
• If you ran the For loop, then at the end of that evaluation i will be 18. This could explain the error message from Part you are seeing. – Arnoud Buzing Aug 11 '16 at 16:51

 matrix = Table[RandomReal[], {n, 1, 17}, {i, 1, 3}]