MATLAB Answers

Converting C++ to MATLAB: statement

1 view (last 30 days)
Hans123 on 15 Jun 2020
Commented: dpb on 15 Jun 2020
I am trying to convert the below C++ line to MATLAB, any help appreciated
A[index1d(x,y,z)] += B[i]*W;

Accepted Answer

dpb on 15 Jun 2020
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.
dpb on 15 Jun 2020
James -- good catch! I meant to add that caveat as well but can be a real bugger to convert if forget or depending just how indices were used...

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!