A. (8 points) We are interested in analyzing weather temperature data for each d
ID: 3863880 • Letter: A
Question
A. (8 points) We are interested in analyzing weather temperature data for each day in a month. We have a vector of the low temperature on each day and a corresponding second vector of the high temperature on each day. The first elements in each vector are for the first day of the month, the second elements in each vector are for the second day of the month, etc. Here are two sample vectors you can use, but your code should work for any two vectors of the same length: lows [59 58 6162 64 6L49 44 50 50 60 47 41 43 54 65 69 58 53 47 40 38 47 43 42 46 44 43 58 44 44]: highs 165 67 67 75 82 76 72 66 63 73 76 68 58 68 71 12 85 78 72 60 55 6173 57 53 5152 66 73 58 62]; Write a single MATLAB statement to create each result. a. How many days had a high temperature over 75? b. Assign the index of the day of the month with the largest difference between the high and low temperature to the variable maxindex. c. What is the average low temperature for days when the high temperature was below 70? d. The first day for the above sample vectors are for a Saturday. Find the average high temperature for all Saturdays in the month.Explanation / Answer
%matlab code
lows = [59 58 61 62 64 61 49 44 50 50 60 47 41 43 54 65 69 58 53 47 40 38 47 43 42 46 44 43 58 44 44];
highs = [65 67 67 75 82 76 72 66 63 73 76 68 58 68 71 72 85 78 72 60 55 61 73 57 53 51 52 66 73 58 62];
%part a
countover75 = 0;
for temp=1:length(highs)
if highs(temp) > 75
countover75 = countover75 +1;
end
end
fprintf('Days with high temperature over : %d ', countover75);
%output: Days with high temperature over : 5
%part b
index = 0;
max=highs(1)-lows(1);
idx = 1;
for i=1:length(highs)
if max > (highs(i)-lows(i))
max = highs(i)-lows(i);
idx = i;
end
end
fprintf('Index with largest difference : %d ',idx);
%output: Index with largest difference : 26
%part c
avgTemp = 0;
counttemp = 0;
for i=1:length(lows)
if highs(i) < 70
avgTemp = avgTemp + lows(i);
counttemp = counttemp + 1;
end
end
fprintf('Average low temperature for days when high temperature was below 70: %0.2f ',(avgTemp/counttemp));
%output: Average low temperature for days when high temperature was below 70: 46.33
%part d
avgTemp = 0;
counttemp = 0;
i = 1;
while i <= length(highs)
avgTemp = avgTemp + highs(i);
i = i + 7;
counttemp = counttemp + 1;
end
fprintf('Average high temperature on saturday: %0.2f ',(avgTemp/counttemp));
%output: Average high temperature on saturday: 67.20
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.