How to add even numbers in matlab

how can i sum all even numbers in matlab.
starting from 2 so : 2
4 would be 2+4=6
7 would be 2+4+6=12
how can i filter out odd numbers? anyone got an idea ?

1 Comment

Stephen23
Stephen23 on 17 May 2021
Edited: Stephen23 on 17 May 2021
The introductory tutorials are the best place to learn basic MATLAB concepts, like how to create vectors and call functions:
These would be a good place to continue reading:

Sign in to comment.

 Accepted Answer

Scott MacKenzie
Scott MacKenzie on 17 May 2021
Edited: Scott MacKenzie on 17 May 2021
x = 100; % the highest number for the sum operation
sum(2:2:x)

More Answers (0)

Categories

Find more on MATLAB 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!