MATLAB Answers

Write a function called freezing that takes a vector of numbers that correspond to daily low temperatures in Fahrenheit. Return numfreeze, the number of days with sub freezing temperatures (that is, lower than 32 F) without using loops. Here is an ex

1.306 views (last 30 days)
Andrew Marttini
Andrew Marttini on 12 Jul 2019
Commented: Rik alrededor de 18 horas ago
This question is soft-locked: new answers that are equivalent to already posted answers may be deleted without prior notice.
Hello there, I am very new to Matlab and I am having trouble with this question. I understand how to make the function work for the given matrix in the problem. However, I cannot find out how to make it work for random temperature vectors. Would anyone mind giving me a hint or helping me out? Would be greatly appreciated. Thank you.

  3 Comments

Andrew Marttini
Andrew Marttini on 12 Jul 2019
So this is what I have so far. Its mostly just the code to solve for the vector thats given.
function numfreeze = freezing (n)
n = [45 21 32 31 51 12]
n1 = n(n<32)
numfreeze = numel(n1)
end

Sign in to comment.

Accepted Answer

Stephan
Stephan on 12 Jul 2019
function numfreeze = freezing (n)
n1 = n(n<32)
numfreeze = numel(n1)
end
Dont overwrite n - it is an input argument

  6 Comments

Show 3 older comments
Agamjyot Singh Chadha
Agamjyot Singh Chadha on 11 May 2020
Using logical can create a bug. For example, if the array 'n' has a value of 0 in it. By using logical the value of the input 0 will be 0 in the array n when instead it should be 1, cause 0 is less than 32. Thus the final result after summing everything in n will get you the wrong answer.

Sign in to comment.

More Answers (3)




Translated by