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

Generate a matrix of random integer temperatures in Fahrenheit from 70 to 100 fo

ID: 3802205 • Letter: G

Question

Generate a matrix of random integer temperatures in Fahrenheit from 70 to 100 for 10 weeks (rows) and 7 days per week (columns). The result should look something like this. Assume the first column is Monday, etc. temperatures = 96 77 95 77 98 80 76 77 89 84 80 95 88 87 98 78 93 93 81 87 72 71 86 94 98 74 87 84 70 80 75 94 79 86 75 88 78 90 91 93 83 72 77 98 74 95 86 100 72 83 73 99 70 94 95 96 72 82 78 94 83 98 75 78 74 74 96 87 87 74 Write Matlab code to answer the following questions. 2a. Which day (1 through 7) had the highest average temperature, and what was that average temperature? 2b. How many days over 90 degree are there? 2c. Which week number had the most temperatures less than 75 degrees?

Explanation / Answer

%matlab code

temperatures = zeros(10,7);
% random matrix
for i=1:10
for j=1:7
temperatures(i,j) = 70+randi(30);
end
end


max = 0;
index = 1;
daysover90 = 0;
max75 = 0;
idx = 1;

for i=1:10
average = 0;
lessthan75max = 0;
for j=1:7
average = average + temperatures(i,j);
if temperatures(i,j) > 90
daysover90 = daysover90 + 1;
end
if temperatures(i,j) < 75;
lessthan75max = lessthan75max + 1;
end
end
average = average/7;
if average > max
max = average;
index = i;
end
  
if lessthan75max > max75
max75 = lessthan75max;
idx = i;
end
end

disp(temperatures);
fprintf('Highest average temperature is %0.2f for day %d ',max,index);
fprintf('Days over 90 degree: %d ',daysover90);
fprintf('Weekwith most temperatures less than 75 degrees: %d ',idx);

%{
output:

83 93 72 99 76 75 75
74 89 84 73 96 100 88
97 76 96 92 85 90 73
86 81 88 93 76 72 74
92 92 89 89 99 96 75
88 78 89 92 89 90 78
98 92 86 78 80 89 96
74 75 89 99 98 80 85
84 95 92 89 75 91 92
99 91 87 74 85 98 86
Highest average temperature is 90.29 for day 5
Days over 90 degree: 25
Weekwith most temperatures less than 75 degrees: 2

%}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote