counting no .of temperature less than 32 in array
Info
This question is closed. Reopen it to edit or answer.
Show older comments
function numfreeze = freezing(v)
count = 0;
i =v()
j = 32
if i < 32
count = count+1
numfreeze = count
else
end
1 Comment
Abhishek singh
on 3 Apr 2019
Answers (6)
Ngei Katumo
on 22 Aug 2019
1 vote
function w = freezing (A)
w = sum (logical (A(A<32)));
end
madhan ravi
on 3 Apr 2019
v=[45 21 32 31 51 12];
threshold=32;
numfreeze = freezing(v,threshold) % function call
function numfreeze = freezing(v,threshold) % function definition
numfreeze = nnz(v<threshold);
end
6 Comments
Abhishek singh
on 3 Apr 2019
madhan ravi
on 3 Apr 2019
Edited: madhan ravi
on 3 Apr 2019
You are pasting the text which you had been asked, if you have any doubts ask.See the answer I gave. Alternatively you can use anonymous function:
v=[45 21 32 31 51 12];
threshold=32;
freeze = @(v,threshold) nnz(v<threshold);
Numfreeze = freeze(v,threshold)
Abhishek singh
on 3 Apr 2019
madhan ravi
on 3 Apr 2019
Edited: madhan ravi
on 15 Sep 2019
edit: After the comment from sir Image Analyst
You should save the function in a separate file named freezing.m. "Getting error" is useless, paste the full error message that you’re getting (everything in red).
Image Analyst
on 11 Jun 2019
You mean freezing.m, since that's what was asked.
madhan ravi
on 15 Sep 2019
Ah yes exactly:)
Nazneen Sayyad
on 10 Jun 2019
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 example run:
numfreeze = freezing([45 21 32 31 51 12])
numfreeze =
3
function numfreeze = freezing(A)
B=A(A<32);
numfreeze=numel(B);
end
Ajith Thomas
on 19 Jul 2019
function numfreeze=freezing(w)
lowerthan_32=w(w<32);
no_logical_values=lowerthan_32(lowerthan_32>=0);
numfreeze=length(no_logical_values);
end
1 Comment
Ajith Thomas
on 19 Jul 2019
function numfreeze=freezing(w)
lowerthan_32=w(w<32);
numfreeze=numel(lowerthan_32);
end
Roshan Singh
on 15 Sep 2019
function numfreeze = freezing(x)
f = x(x<32);
numfreeze = length(f);
end
MADHURJYA DAS
on 30 Aug 2020
function numfreeze=freezing(A)
x=(A<32);
numfreeze=sum(x(:));
end
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!