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

2 views (last 30 days)
%% 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 Comments
Rik
Rik on 15 Dec 2021
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

Sign in to comment.

Accepted Answer

Scott MacKenzie
Scott MacKenzie on 26 Jun 2021
for i = 1:length(a)
s = sum(a)-a(i)
end

More Answers (0)

Categories

Find more on Loops and Conditional Statements 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!