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

12 views (last 30 days)
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)

Categories

Find more on Elementary Math in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by