Making a sum into a for loop

5 Ansichten (letzte 30 Tage)
Cheggers
Cheggers am 3 Aug. 2021
Bearbeitet: Jakeb Chouinard am 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

Akzeptierte Antwort

Jakeb Chouinard
Jakeb Chouinard am 3 Aug. 2021
Bearbeitet: Jakeb Chouinard am 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.
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);

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by