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;
댓글 수: 0
채택된 답변
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
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
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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!