how to implementing energy function?
显示 更早的评论

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
2020-4-9
编辑:Ameer Hamza
2020-4-9
For loop is not needed. Use can use vectorized operation
Sum = sum(V.^2, 'all');
16 个评论
No not working getting error.
What is the error? Please paste complete error message.
Which MATLAB release are you using?
'Subscript indices must either be real positive integers or logicals.'
In MATLAB 2016b, change the line to
Sum = sum(V(:).^2);
Same error.
what about
sum(sum(sum(V.^2)))
make sure that no variable sum() is defined in your workspace. run
clear sum
before running the code.
I am getting again same error.
I am not sure about the issue. There seem to be some issue with you MATLAB installation. What is the output of
which sum
Sorry, the correct command was
clear sum
not clear run, I have updated my comment. Try it again.
Thank you so much it is working.
I am having some confusion with the other two equations, will u plz help me out ???
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 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)

