Q:

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

0

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. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now