Pass pointer to function as in C

3 visualizaciones (últimos 30 días)
DC Fang
DC Fang el 17 de Dic. de 2021
Comentada: DC Fang el 18 de Dic. de 2021
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] = ...;
}

Respuesta aceptada

Voss
Voss el 17 de Dic. de 2021
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 comentario
DC Fang
DC Fang el 18 de Dic. de 2021
Many thanks Benjamin, that solves my question!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Software Development Tools en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by