MATLAB: How to find average of column of matrix

averagehomeworkno attempt

I have a matrix of 12 columns and 36 rows . I want to do the average of all the columns and get the results separately. I've attached the data file with this. Please, find the attachment . Also, 've to do with the help of loops, not direct command.

Best Answer

You didn't attach anything, so I'll just assume you can use csvread() or importdata() to get your data into an array m. Then to do the average with loops, not functions like mean() or sum():
Also, like Mike I don't know what you mean by "average of all the columns" - it's ambiguous. It could mean for each row, get the average over all the columns in that row. Or it could mean for each column, get the average of all the values (which span all the rows in the column). I'm going to assume you want one mean for each column and average over all the rows in each column.
[rows, columns] = size(m);
for col = 1 : columns
theSum = 0;
for row = 1 : rows
theSum = theSum + m(row, col);
end
% Now get the mean over all values in this column.
columnMeans(col) = theSum / rows;
end