how to implementing energy function?

5 次查看(过去 30 天)
i want to implement this above energy function and i tried this following code, but i am getting 'Index exceeds matrix dimensions.' error. How can do this?
e=[];
V=WT.dec{1,1};
for x=1:17
for y=1:19
for z=1:18
e = e + (V(x,y,z))^2;
end
end
end

采纳的回答

Ameer Hamza
Ameer Hamza 2020-4-9
编辑:Ameer Hamza 2020-4-9
For loop is not needed. Use can use vectorized operation
Sum = sum(V.^2, 'all');
  16 个评论
Ameer Hamza
Ameer Hamza 2020-4-11
编辑:Ameer Hamza 2020-4-11
Please create a new question and paste the link in the comment below. I will try to help.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by