What I am wondering about is how does matlab pass a structure to a function or method of a matlab class and how does it return it. Lets say I have the following code
foo.var1 = 3;
foo.var2 = [1 2 3 4];
function return_foo = my_fun(structure)
structure.var1 = structure.var1 + 7;
structure.var2 = 2*structure.var2;
return_foo = structure;
end
and then call my_fun(foo)
. Does matlab do a deep copy of foo and passes it to the function or does it just pass a pointer? Same question for the assignment return_foo = structure;
and for returning return_foo
to the caller.
Edit: And does that behavior change when the data held by the structure gets more 'complex', e.g. nested structures, arrays, ...