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

MATLAB Code: MATLAB Code: The following were the daily maximum temperatures (Cel

ID: 3348888 • Letter: M

Question

MATLAB Code:

MATLAB Code:

The following were the daily maximum temperatures (Celsius) in Philadelphia during the month of March 2004: 24, 13, 23, 14, 11, 19, 9, 23, 25, 20, 22, 27, 13, 29, 30, 32, 40, 42, 35, 17, 25, 29, 33, 28, 45, 50, 33, 32, 21, 30,31. Write a script, and use relational and logical operators to determine the following: a- The number of days the temperature was above 30 Celsius b- The number of days the temperature was between 30 Celsius and 40 c- Use disp to display the result on the screen.

Explanation / Answer

Ans)

==============MATLAB code with comments=========


% T is vector representing temperatures given
T=[24 13 23 14 11 19 9 23 25 20 22 27 13 29 30 32 40 42 35 17 25 29 33 28 45 50 33 32 21 30 31];

Tabove30=T(T>30);%this vector contains temperatures above 30
noDaysTabove30=length(Tabove30);%this vector counts no of days where T>30

X = sprintf('no of days where temperature is above 30: %d ',noDaysTabove30);
disp(X)

Tbtn30nd40=T(T>30 & T<40);%this vector contains temperatures above 30
noDaysTbtn30nd40=length(Tbtn30nd40);%this vector counts no of days where T>30 and T<40

Y = sprintf('no of days where temperature is between 30 and 40: %d ',noDaysTbtn30nd40);
disp(Y)

%==================================

when you run the above code result in command window is

>> script1
no of days where temperature is above 30: 10
no of days where temperature is between 30 and 40: 6

%========================