find an average of ten numbers in matlab

To find the average of ten numbers in MATLAB, store the numbers in an array and use the mean function:

main.m
% Declare an array of ten numbers
numbers = [3, 7, 9, 12, 6, 18, 2, 4, 10, 15];

% Find the average of the numbers using the mean function
avg = mean(numbers);
160 chars
6 lines

The mean function takes the average of all elements in the input array. In this case, it takes the average of the ten numbers in the numbers array and assigns it to the avg variable.

gistlibby LogSnag