Making a sum into a for loop

1 回表示 (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by