Write a function that will receive a matrix as an input argument, and will calculate and return the overall average of all numbers in the matrix. Use loops, not built-in functions, to calculate the average
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:5| Question number:17.5
All Answers
total answers (1)
matave.m
function outave = matave(mat)
% Calculates the overall average of numbers in a matrix
% using the programming methods
% Format of call: matave(matrix)
% Returns the average of all elements
mysum = 0;
[r c] = size(mat);
for i = 1:r
for j = 1:c
mysum = mysum + mat(i,j);
end
end
outave = mysum/(r*c);
end
need an explanation for this answer? contact us directly to get an explanation for this answer