Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a MATLAB script file that calculates the mean of N numbers. The number

ID: 648305 • Letter: 1

Question

1. Write a MATLAB script file that calculates the mean of N numbers. The number N and the actual N umber values are being asked from the user on the screen.

2. Write a MATLAB function that that converts miles to kilometers, meters, centimeters and millimeters. Test your code using 5 different values for miles and display the results in a table format using fprinf. The table header should look like this:

           

            Miles       Kilometers       Meters         Centimeters        Millimeters

Explanation / Answer

1)

prompt = 'How many values you want size of array ';
n = input(prompt)
A = zeros(1,n)

for i = 1:n
prompt = 'Enter number ';
x = input(prompt)
A(i) = x
end
mean(A)

2)

miles=100
a = convlength(miles,'mi','km')
b = convlength(miles,'mi','m')
c = convlength(miles,'mi','cm')
d = convlength(miles,'mi','mm')
formatSpec = '%4 %4.2f kilometers or %4.2f meters or %4.2f centimeters or %8.3f millimetres ';
fprintf(formatSpec,miles,a,b,c,d)