Problem 367. Specific Element Count
Solution Stats
Problem Comments
Solution Comments
-
1 Comment
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
-
1 Comment
The comment about NaNs being equal is rather vague, clarify or give a specific example
-
2 Comments
NaN==NaN gives 0 help me
Use isnan keyword. isnan(NaN) gives 1
-
1 Comment
There should be a test to stop this from passing
-
1 Comment
This just got lucky on the test suite. It would fail on ecount(1:12,2), for example.
Problem Recent Solvers816
Suggested Problems
-
Remove the polynomials that have positive real elements of their roots.
1227 Solvers
-
Return unique values without sorting
822 Solvers
-
Cell Counting: How Many Draws?
1324 Solvers
-
6298 Solvers
-
Convert from Fahrenheit to Celsius
17015 Solvers
More from this Author56
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!