Making a sum into a for loop

5 visualizzazioni (ultimi 30 giorni)
Cheggers
Cheggers il 3 Ago 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

Risposta accettata

Jakeb Chouinard
Jakeb Chouinard il 3 Ago 2021
Modificato: Jakeb Chouinard il 3 Ago 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);

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by