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

조회 수: 3 (최근 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

댓글을 달려면 로그인하십시오.

채택된 답변

Scott MacKenzie
Scott MacKenzie 2021년 6월 26일
for i = 1:length(a)
s = sum(a)-a(i)
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by