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

4 ビュー (過去 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 件のコメント
Walter Roberson
Walter Roberson 2017 年 11 月 15 日
I suspect this is a case where a loop would be the easiest.

サインインしてコメントする。

採用された回答

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));
  2 件のコメント
Bashir Yusuf Bichi
Bashir Yusuf Bichi 2017 年 11 月 16 日
pls if I have a vector a=[30.85,4.11,6.17,2.51,2.28]; b=sum(a)/numel(a); I want to find the closes value to the average b and its indices, what will I do?
Andrei Bobrov
Andrei Bobrov 2017 年 11 月 16 日
a=[30.85,4.11,6.17,2.51,2.28];
b = mean(a);
t = a < b;
vals = a(t);
indices = find(t);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by