Pass pointer to function as in C

조회 수: 3 (최근 30일)
DC Fang
DC Fang 2021년 12월 17일
댓글: DC Fang 2021년 12월 18일
I'm a C/C++ programmer and am new to MATLAB. May I ask if I could do the below equivalence in MATLAB, where I have a C subroutine that updates one array from the values of another array?
void vec_update(double* vec1, double* vec2)
{
vec2[0] = vec1[0] + vec1[1] + ... ;
...;
vec2[N] = ...;
}

채택된 답변

Voss
Voss 2021년 12월 17일
Here is the equivalent MATLAB-style pseudo-code:
function vec2 = vec_update(vec1, vec2)
vec2(1) = vec1(1) + vec1(2) + ... ;
...;
vec2(end) = ...;
end
Note that in MATLAB you have to specify the modified vector as an output argument.
  댓글 수: 1
DC Fang
DC Fang 2021년 12월 18일
Many thanks Benjamin, that solves my question!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by