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

1 vue (au cours des 30 derniers jours)
%% 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 commentaires
Rik
Rik le 15 Déc 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
Rena Berman
Rena Berman le 16 Déc 2021
(Answers Dev) Restored edit

Connectez-vous pour commenter.

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by