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일

1 개 추천

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

Hans123
Hans123 2020년 6월 15일
Thank you!
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개)

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

태그

질문:

2020년 6월 15일

댓글:

dpb
2020년 6월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by