Problem 2350. What is Sum Of all elements of Matrix
Given the matrix x, return the sum of all elements of matrix.
Example:
Input x = [ 1 2 0 0 0 0 6 9 3 3 ] Output y is 24.
Input x = [ 1 NaN 0 0 0 0 6 9 3 3 ] Output y is NaN.
Solution Stats
Problem Comments
-
6 Comments
isequal(NaN, NaN) always return false. By definition Nans are not equal to each other. If you want test that a result is NaN, either use isnan, or use isequaln
The problem is unsolvable due to the second test.
isequalwithequalnans
I agree guys! something wrong
please use the function: isequalwithequalnans
;-)
Thanks for the suggestions. I fixed with isequalwithequalnans.
Solution Comments
Show commentsProblem Recent Solvers419
Suggested Problems
-
Flip the main diagonal of a matrix
828 Solvers
-
Number of 1s in a binary string
9568 Solvers
-
Count decimal digits of a number
227 Solvers
-
Add a row of zeros on top of a matrix
253 Solvers
-
Back to basics - mean of corner elements of a matrix
427 Solvers
More from this Author6
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!