Question

The
global temperature of the planet was recorded every week for 5
years. That makes 52*5 = 260 temperatures. Write an algorithm
having: - as a parameter, the list of real values corresponding to
the 260 temperatures in the order of recording: 1st week of the 1st
year, 2nd week of the 1st year, ..., 52nd week of the 1st year, 1st
week of the 2nd year, 2nd week of the 2nd year, ..., 52nd week of
the 5th year ; - as a result, the list of the 5 average
temperatures of each year (i.e., the list of real temperatures
constituted by of the average of the first 52 values, then the
average of the next 52 values, and so on).

Answer #1

Required Matlab code with explanatory comments is given below:

function avg=Q_myavg(A)

avg=zeros(1,5); %initialize averages array

for k=1:5 %for each year

avg(k)=mean(A(52*(k-1)+1:52*k)); %find the
average of each year

end

end

Sample usage:

*Hope this was helpful. Please do leave a positive rating if
you liked this answer. Thanks and have a good day!*

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 7 minutes ago

asked 7 minutes ago

asked 9 minutes ago

asked 9 minutes ago

asked 19 minutes ago

asked 23 minutes ago

asked 28 minutes ago

asked 30 minutes ago

asked 36 minutes ago

asked 38 minutes ago

asked 42 minutes ago

asked 48 minutes ago