Question

I need help on calculating a current overall average for this data in MatLab. I need...

I need help on calculating a current overall average for this data in MatLab. I need to make another vector for the data where each position is a current average. I've looked around online to try and get an idea of what to do and I saw the things about there being a moving average function or using filter. But we haven't talked about those in my class so I can't use them. I think a for loop could do it but I can't figure it out. The data is 97, 80, 79, 64, 71, 77, 95, 81, 73, 84, 86, 96, 83, 69, 64, 66, 59, 72, 67, 65, 65, 64, 59, 68, 75, 62, 77, 58, 66, 56, 53, 62. The output for the home score should be 97, 88. 85.3, 80.0, 78.2, 80.4, 80.5, 79.7, 80.1, 80.6, 81.9, 82.0, 81.1, 79.9, 79.1, 77.9, 77.6, 77.0, 76.4, 75.8, 75.0, 74.7, 74.8, 74.2, 74.3, 73.7, 73.5, 72.9, 72.2, 71.0.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code:

numbers=0;

result=0;

while 1

n=str2double(input('Enter an integer: ', 's'));

result=result*numbers+n;

numbers=numbers+1;

result=result/numbers;

fprintf('Current average is: %f\n', result);

end

For indendation:

Sample i/o:

Explanation:

Average is (sum of all numbers)/count. Hence in each iteration find the previous sum by multiplying average*count. Now add value read from console to previous sum and increment the count and print the average.

Add a comment
Know the answer?
Add Answer to:
I need help on calculating a current overall average for this data in MatLab. I need...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT