Making a sum into a for loop

조회 수: 3 (최근 30일)
Cheggers
Cheggers 2021년 8월 3일
편집: Jakeb Chouinard 2021년 8월 3일
i have a set of equations i would like to sum.
ND = ((multiND(1,1))/sigmapi) * exp(-((x-(isofm(1,1))^2)/(2*(sigma^2))));
ND2 = ((multiND(2,1))/sigmapi) * exp(-((x-(isofm(2,1))^2)/(2*(sigma^2))));
.
.
.
and so on up to the number of variables in multiND
at the end i did sum = (ND + ND2........)
All this works but i would like to put it into a for loop but i am struggling with the summation part at the end.
Any help would be appreciated

채택된 답변

Jakeb Chouinard
Jakeb Chouinard 2021년 8월 3일
편집: Jakeb Chouinard 2021년 8월 3일
I'm not entirely sure of the data you're working with, but I can make the suggestions below:
In a for loop, you can iteratively set values to indices of an array up until the row size of your multiND. Once these are all set, you can use the sum function to get the actual sumof all the ND values.
Cheers,
Jakeb
Ex.
x = rand(32,1);
s = length(x);
for idxSomething = 1:32
s(idxSomething,1) = x(idxSomething,1)*32+32;
end
sumX = sum(s);

추가 답변 (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