Write a single line code to sum all the odd numbers of an array.

6 views (last 30 days)
Abhi Jain
Abhi Jain on 4 Oct 2016
Commented: Abhi Jain on 4 Oct 2016
The code should contain only one line.

Accepted Answer

Abhishek Jain
Abhishek Jain on 4 Oct 2016
You can use this code:
y = sum(x(rem(x,2)==1));

More Answers (0)

Community Treasure Hunt

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

Start Hunting!