how i implement this equation.

4 ビュー (過去 30 日間)
muhammad mazhar
muhammad mazhar 2019 年 10 月 8 日
コメント済み: muhammad mazhar 2019 年 10 月 9 日
hey guys,
i am try to implement to loop of follow equation
where Eci is the energy charge by the ith sensor.
hdghd.png
  2 件のコメント
muhammad mazhar
muhammad mazhar 2019 年 10 月 8 日
Ne=9;
foi i= 1:1:100;
for e=1:1:9;
Eci =sum (Eci,Ne,1,9)
end
end
but error appear in the formula which used in loop
muhammad mazhar
muhammad mazhar 2019 年 10 月 8 日
thanks for reply but after apply loop in statement there be error

サインインしてコメントする。

採用された回答

Daniel M
Daniel M 2019 年 10 月 8 日
編集済み: Daniel M 2019 年 10 月 8 日
Why do you want a loop to do this simple equation anyways? Ok here you go...
clearvars;
Ne = 9;
Ni = 100;
Eci = rand(Ni,Ne); % I'm assuming this data exists
Ec = zeros(Ni,1);
for i = 1:Ni
tmp = 0;
for e = 1:Ne
Ec(i) = tmp + Eci(i,e);
end
end
Or you could just call sum() once to vectorize the code. I will leave that up to you.
  1 件のコメント
muhammad mazhar
muhammad mazhar 2019 年 10 月 9 日
thanks dear daniel.because of you i have learnt the problem in coding.
Regard:M.Mazhar

サインインしてコメントする。

その他の回答 (1 件)

Karim
Karim 2019 年 10 月 8 日
編集済み: Karim 2019 年 10 月 8 日
This depends on the format of Ec... is it a matrix or cell array?
Assuming Ec is a matrix with "i" rows and "e" columns...
Ec = zeros(c,1);
for i = 1:c
Ec(i) = sum(Ec_ie(i,:));
end
or in a single line:
Ec = sum(Ec_ie,2);

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by