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

1 visualización (últimos 30 días)
%% 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 comentarios
Rik
Rik el 15 de Dic. de 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

Iniciar sesión para comentar.

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by