how to use Subscript in for loop

3 ビュー (過去 30 日間)
reza hamzeh
reza hamzeh 2019 年 10 月 20 日
回答済み: Dimitris Kalogiros 2019 年 10 月 20 日
hi.
i have some mathematica codes that i want to change them to matlab codes. i think its possible to write these codes as two for-loops in matlab. but unfortunetly
i dont know how to do that. in mathematica its easy to do that with help of Subscripts but there is no Subscript in matlab to do that.
tr=trace
codes.jpg
the code should be something like this ?? plz help me
for i=0:3
for j=0:3
p{i,j}=trace(e{i}*ro)*trace(e{j}*ro)
end
end
  1 件のコメント
Star Strider
Star Strider 2019 年 10 月 20 日
You need to start the indices with 1 instead of 0, since MATLAB subscripts are defined as integers greater than 0.
Otherwise, it appears to be correct, assuming that the elements of cell array ‘e’ are square matrices.

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

回答 (1 件)

Dimitris Kalogiros
Dimitris Kalogiros 2019 年 10 月 20 日
What is Tr [ ] at your mathematica code ? Is it an array or a function (I am asking because I 've no experience on mathematica).
You must be aware of the fact that indexes in matlab starts from 1 . For example if A is a vector of 5 elements, then A(1) is is the first element. On the other hand A(0) , produces an execution error.
So, the matlab code you suggest has to be corrected in one or two places:
  • i and j indexes must have a range from 1 to 4
  • depending on the value of e{i}*ro or e{j}*ro, maybe you have to add +1, when you use them as indexes.

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by