Am trying to reduce a vector by summing some elements in the vector to form another vecter

2 次查看(过去 30 天)
example if v=[40,34,10,8,6,2] then the new vector will make 40 to be the reference point. after comparing each element the new vector will be N=[40,34,26]
  6 个评论

请先登录,再进行评论。

采纳的回答

Andrei Bobrov
Andrei Bobrov 2017-11-15
编辑:Andrei Bobrov 2017-11-15
b = cumsum(hankel(v));
k = max(b .* (b <= 40));
N = k(cumsum(k) <= b(end,1));
or
t = cumsum(hankel(v));
t = max(t.*(t <= 40));
N = t(cumsum(t) <= sum(v));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by