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

2 Ansichten (letzte 30 Tage)
%% 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 Kommentare
Rik
Rik am 15 Dez. 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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by