Converting C++ to MATLAB: statement

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by