Converting C++ to MATLAB: statement

1 回表示 (過去 30 日間)
Hans123
Hans123 2020 年 6 月 15 日
コメント済み: dpb 2020 年 6 月 15 日
I am trying to convert the below C++ line to MATLAB, any help appreciated
A[index1d(x,y,z)] += B[i]*W;

採用された回答

dpb
dpb 2020 年 6 月 15 日
A[index1d(x,y,z)] = A[index1d(x,y,z)] + B[i]*W;
in C/C++
Presuming conformance of dimensions, etc.,
A(index1d(x,y,z)) = A(index1d(x,y,z)) + B(i)*W;
in MATLAB replacing the braces.
  3 件のコメント
James Tursa
James Tursa 2020 年 6 月 15 日
Since C++ is 0-based indexing and MATLAB is 1-based indexing, you will probably need to add 1 to your indexes in the above conversion, either explicitly or as part of upstream code.
dpb
dpb 2020 年 6 月 15 日
James -- good catch! I meant to add that caveat as well but forgot...it can be a real bugger to convert if forget or depending just how indices were used...

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by