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

2 ビュー (過去 30 日間)
Abdlrahman Hazem
Abdlrahman Hazem 2021 年 1 月 14 日
回答済み: Stephan Ciobanu 2021 年 1 月 14 日
The question is
Write one Matlab command to get the following from vector x:
  • Sum the values of positive even elements

回答 (1 件)

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

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by