how to implementing energy function?
조회 수: 3 (최근 30일)
이전 댓글 표시
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/283037/image.jpeg)
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
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!