The below code fails for the input:
assert(isequal(ecount([1 1 1 1 NaN NaN 1 1],NaN),2))
Can anyone show me the error?
function ct = ecount(v,e)
s=0;
for i=1:length(v)
if v(i)==e
s=s+1;
elseif v(i)=='NaN'
s=s+1;
i=i+1;
end
ct =s;
end
The comment about NaNs being equal is rather vague, clarify or give a specific example
NaN==NaN gives 0 help me
Use isnan keyword. isnan(NaN) gives 1
There should be a test to stop this from passing
This just got lucky on the test suite. It would fail on ecount(1:12,2), for example.
The Goldbach Conjecture, Part 2
1286 Solvers
Vectorize the digits of an Integer
269 Solvers
421 Solvers
Number of Even Elements in Fibonacci Sequence
666 Solvers
Convert from Fahrenheit to Celsius
7274 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!