# 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 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.

the cyclist on 12 Jul 2019
Upload your code here, and maybe some folks will give you some hints.
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
Sai Swaroop Maram on 30 Jul 2020 at 10:29
function numfreeze=freezing(T)
T(T<32)=1;
T(T>=32)=0;
numfreeze=sum(T);

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

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.
Walter Roberson on 11 May 2020
Agamjyot is correct.
Hari Kiran Tirumaladasu on 5 Jun 2020
Tahsin Hossain,
Try this code,
function numfreeze = freezing(A)
n = (A<32);
numfreeze = sum(n);

Vineet Singhal on 14 Oct 2019
function numfreeze = freezing(v)
a= length(v(v<32));
numfreeze =a;
end

mohammad elyoussef on 4 Apr 2020
function b = freezing(a)
f = a < 32;
b = sum(f);

Yash Agarwal on 22 Apr 2020
function numfreeze = freezing(A)
B = A(A<32);
numfreeze = size(B,2);
end

#### 1 Comment

Rik alrededor de 18 horas ago
You are not promissed A is a either a row or column vector, so your solution should support both input types.