in each iteration I want to get the sum of all elements except of the i element

14 ビュー (過去 30 日間)
%% for example in the second itreation (i=2) I want the sum of all elements except the 3 (second element)
a=[1 3 2 1 4 2 1 5 1 2]
for i=1:length(a)
s= sum(aa(d+1:end))
end
  2 件のコメント
Rik
Rik 2021 年 12 月 15 日
in each iteration I want to get the sum of all elements except of the i element
%% for example in the second itreation (i=2) I want the sum of all elements except the 3 (second element)
a=[1 3 2 1 4 2 1 5 1 2]
for i=1:length(a)
s= sum(aa(d+1:end))
end
Rena Berman
Rena Berman 2021 年 12 月 16 日
(Answers Dev) Restored edit

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

採用された回答

Scott MacKenzie
Scott MacKenzie 2021 年 6 月 26 日
for i = 1:length(a)
s = sum(a)-a(i)
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by