Pass pointer to function as in C

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 日

0 投票

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 件)

カテゴリ

ヘルプ センター および File ExchangeSoftware Development Tools についてさらに検索

製品

リリース

R2019a

タグ

質問済み:

2021 年 12 月 17 日

コメント済み:

2021 年 12 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by