Clear Filters
Clear Filters

How to get Sum the values of positive even elements from vector x using only one command?

2 views (last 30 days)
The question is
Write one Matlab command to get the following from vector x:
  • Sum the values of positive even elements

Answers (1)

Stephan Ciobanu
Stephan Ciobanu on 14 Jan 2021
% Hi!
% You can try this:
My_sum = sum((x(2:2:end)>0).*x(2:2:end));

Categories

Find more on Get Started with 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!