Generate a block of MATLAB code that computes the average of

Generate a block of MATLAB code that computes the average of a group of numbers. Collect the number of values from the user as well as the values for the numbers to be averaged. Place the values to be averaged in a row array. Display the value for the average as a floating point number, with a maximum field width of 6 characters, and with accuracy to 4 decimal places.

Solution

MATLAB CODE :-

function average = avg(A,C)

clear

clc
i = 1;
n = input(\'Number of Values = \ \');
disp(\'Enter Numbers\')
C = 0;
for i = 1:1:n
    B = input(\'\');
    A(1,i) = B;
    i = i+1;
    C = C+B;
end
disp(\'Entered NUmbers in row matric\')
A
Average = C/(i-1);
sprintf(\'Average = %.4f\',Average)

OUTPUT :-

Number of Values =
10
Enter Numbers
1
2
3
4
5
6
7
8
9
10
Entered NUmbers in row matric

A =

     1     2     3     4     5     6     7     8     9    10


ans =

Average = 5.5000

 Generate a block of MATLAB code that computes the average of a group of numbers. Collect the number of values from the user as well as the values for the numbe

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site