255 views (last 30 days)

Show older comments

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.

Sai Swaroop Maram
on 30 Jul 2020

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

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

Yash Agarwal
on 22 Apr 2020

function numfreeze = freezing(A)

B = A(A<32);

numfreeze = size(B,2);

end

Rik
on 13 Aug 2020

Rajeev Mehndiratta
on 28 Oct 2020

function numfreeze = freezing(V)

A=0

V

V(V<32) = A

A =logical(V)

B=sum(A)

numfreeze=B

end

Rik
on 28 Oct 2020

You're correct, this solution didn't exist in this thread yet, although I would clean it up to this:

function numfreeze = freezing(V)

V(V<32) = 0;

V = logical(V);

numfreeze = sum(V);

end

Nadeem U Rehman
on 10 Dec 2020

function numfreeze = freezing(A)

F = A(A<32);

[row column] = size(A);

if size(A) == [1 column]

numfreeze = size(F,2);

else

numfreeze = size(F,1);

end

end

Rik
on 10 Dec 2020

These homework solutions are probably not the best place to get feedback. After completing the Onramp tutorial (which is provided for free by Mathworks), I would suggest looking at this thread.

And where you went wrong is in assuming what == does, instead of reading the documentation. There is an important difference between equals (which is called when you write ==) and isequal. size(A)==[row column] will result in a two-element logical vector if A is a vector or 2D array (and an error if A has more dimensions).

% Let's take a look at what if does:

A=[]; if A, disp(A),end

A=true; if A, disp(A),end

A=[true false]; if A, disp(A),end

A=[true true]; if A, disp(A),end

A=[false true]; if A, disp(A),end

A=[false false];if A, disp(A),end

Did you expect these results? What does this say about how your code would work?

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

Start Hunting!