Within Matlab I am trying to write a function I am trying to

Within Matlab I am trying to write a function:

I am trying to write a function that calculates the average of a sequence of numbers in an array. It should take in an input array and prints out the average with with only two place values after decimal. If I type these into the Command window individually I get the write answer but I want to creat a function to allow input and output answer in the right decimal form.

A = [2, 4, 5, 6, 6, 6];

ANSWER = mean (A);

fprintf(\'%.2f\',ANSWER)

I get the following answer of 4.83. This is write but I am entering each line individually.

Example 1: input array is [2 4 5 6 6 6], should ouptut 4.83

Solution

I think you have completed everything . You just need to create a Matlab script (A file with .m extension) and execute it . Not sure in which environment you are running your programs. Following is the matlab function , just copy it in your script and execute it

you can further add calls to this function in the script itself using following statement :

ar = [ 2,4,5,6,6,6 ]

print_mean(ar)

Please comment if you are looking for something else too .

Within Matlab I am trying to write a function: I am trying to write a function that calculates the average of a sequence of numbers in an array. It should take

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site