Making a sum into a for loop

3 views (last 30 days)
Cheggers on 3 Aug 2021
Edited: Jakeb Chouinard on 3 Aug 2021
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

Accepted Answer

Jakeb Chouinard
Jakeb Chouinard on 3 Aug 2021
Edited: Jakeb Chouinard on 3 Aug 2021
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.
x = rand(32,1);
s = length(x);
for idxSomething = 1:32
s(idxSomething,1) = x(idxSomething,1)*32+32;
sumX = sum(s);

More Answers (0)


Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!