The prompt and my initial work is in the code below. This is my first time using for loops and am having difficulties. I understand that I have to somehow have the code check each element to see if it is >50, and if it is, add one to some variable in order to total the number of times this occurs. Then I have to have the code add up all values and divide by the number of values (this I have no idea how to do).
We have to use a for loop and so I tried to get the code to check if the tempv is in the range of 50 to 75 (as 75 is the largest value), and if it falls in this range, it adds one to a variable that starts at zero. But when I run the code it just spits out the variable from 0 to 26 (because of 50 to 75). What am I doing wrong???
clear, clc tempv = [50, 60, 65, 30, 40, 66, 30, 55, 72, 72, 75, 50, 60, 65, 30, 40, ... 66, 30, 55, 63, 72, 75, 50, 60, 65, 30, 40, 66, 30, 55, 53];%
% Q3.1 Approach 1: use a for loop to implement the requirement % Write your code here:
n=0; for tempv=50:75 n=n+1; fprintf('In May the number of days the T was over 50 was: %i\n', n) end
And here is the command window output:
In May the number of days the T was over 50 was: 1
In May the number of days the T was over 50 was: 2
In May the number of days the T was over 50 was: 3
In May the number of days the T was over 50 was: 4
In May the number of days the T was over 50 was: 5
In May the number of days the T was over 50 was: 6
In May the number of days the T was over 50 was: 7
In May the number of days the T was over 50 was: 8
In May the number of days the T was over 50 was: 9
In May the number of days the T was over 50 was: 10
In May the number of days the T was over 50 was: 11
In May the number of days the T was over 50 was: 12
In May the number of days the T was over 50 was: 13
In May the number of days the T was over 50 was: 14
In May the number of days the T was over 50 was: 15
In May the number of days the T was over 50 was: 16
In May the number of days the T was over 50 was: 17
In May the number of days the T was over 50 was: 18
In May the number of days the T was over 50 was: 19
In May the number of days the T was over 50 was: 20
In May the number of days the T was over 50 was: 21
In May the number of days the T was over 50 was: 22
In May the number of days the T was over 50 was: 23
In May the number of days the T was over 50 was: 24
In May the number of days the T was over 50 was: 25
In May the number of days the T was over 50 was: 26