0

Does Matlab allows editing a function argument? I was passing a struct with several fields that were populated/updated each call, and realized that the variable value had not changed at all. I ended up returning the input variable as function output, but was wondering if it somehow possible to just pass the variable handle/reference to the function?

joaocandre
  • 1,621
  • 4
  • 25
  • 42

1 Answers1

0

Changing function's argument with these changes being seen outside of the funtion's scope is called passing by reference. Matlab passes data variables by value except for the handle objects, which are passed by reference. This link has it all https://au.mathworks.com/matlabcentral/answers/152-can-matlab-pass-by-reference

question about passing by reference vs passing by value: What's the difference between passing by reference vs. passing by value?

my favourite gif explaining this topic https://blog.penjee.com/wp-content/uploads/2015/02/pass-by-reference-vs-pass-by-value-animation.gif

Artyom Emelyanenko
  • 1,323
  • 1
  • 11
  • 16