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 件のコメント
Mehul Jain
2020 年 4 月 9 日
No not working getting error.
Ameer Hamza
2020 年 4 月 9 日
What is the error? Please paste complete error message.
Which MATLAB release are you using?
Mehul Jain
2020 年 4 月 11 日
'Subscript indices must either be real positive integers or logicals.'
Mehul Jain
2020 年 4 月 11 日
R2016b
Ameer Hamza
2020 年 4 月 11 日
In MATLAB 2016b, change the line to
Sum = sum(V(:).^2);
Mehul Jain
2020 年 4 月 11 日
Same error.
Ameer Hamza
2020 年 4 月 11 日
what about
sum(sum(sum(V.^2)))
Ameer Hamza
2020 年 4 月 11 日
編集済み: Ameer Hamza
2020 年 4 月 11 日
make sure that no variable sum() is defined in your workspace. run
clear sum
before running the code.
Mehul Jain
2020 年 4 月 11 日
I am getting again same error.
Ameer Hamza
2020 年 4 月 11 日
I am not sure about the issue. There seem to be some issue with you MATLAB installation. What is the output of
which sum
Mehul Jain
2020 年 4 月 11 日

Ameer Hamza
2020 年 4 月 11 日
編集済み: Ameer Hamza
2020 年 4 月 11 日
Sorry, the correct command was
clear sum
not clear run, I have updated my comment. Try it again.
Mehul Jain
2020 年 4 月 11 日
Thank you so much it is working.
Mehul Jain
2020 年 4 月 11 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
