794 views (last 30 days)

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.

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

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

Lokesh Sahu
on 30 Aug 2020 at 15:07

function numfreez = freezing(x)

numfreez = length (x (x<32)) ;

end

%you dont even need that a, just use numfreez directly

Yash Agarwal
on 22 Apr 2020

function numfreeze = freezing(A)

B = A(A<32);

numfreeze = size(B,2);

end

Rik
on 13 Aug 2020

Jessica Trehan
about 2 hours ago

function numfreeze = freezing(x)

n = x(x<32);

numfreeze= length(n);

end

%The most accurate and compact code.

Rik
about 2 hours ago

Wrong. This would be more compact:

freezing=@(x)length(x(x<32));

A solution equivalent to yours was also already posted on this thread. Why should your answer not be deleted?

Walter Roberson
about 1 hour ago

Opportunities for recent engineering grads.

Apply TodayFind the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 3 Comments

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/471385-write-a-function-called-freezing-that-takes-a-vector-of-numbers-that-correspond-to-daily-low-tempera#comment_723720

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/471385-write-a-function-called-freezing-that-takes-a-vector-of-numbers-that-correspond-to-daily-low-tempera#comment_723720

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/471385-write-a-function-called-freezing-that-takes-a-vector-of-numbers-that-correspond-to-daily-low-tempera#comment_723723

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/471385-write-a-function-called-freezing-that-takes-a-vector-of-numbers-that-correspond-to-daily-low-tempera#comment_723723

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/471385-write-a-function-called-freezing-that-takes-a-vector-of-numbers-that-correspond-to-daily-low-tempera#comment_955051

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/471385-write-a-function-called-freezing-that-takes-a-vector-of-numbers-that-correspond-to-daily-low-tempera#comment_955051

Sign in to comment.