Hello,
I am trying to use pass by reference using handle objects.
The scenario I have right now is I have an array of handle objects defined by:
classdef unit < handle
and I'd like to pass an array of such an object to a function which in turn sets a callback to a button that once pressed, should add a new element to that array. I have managed to pass the array through to the callback function. When I change the value of the properties of any of the original elements, the original array gets updated, as expected. However, when I add an element, the new element is lost when the callback function completes, as expected I suppose.
But since I cannot return anything from a callback, what method can I use to add this element and have it update the original object? A couple potential solutions I've thought of:
1. Do I need to pre-augment the array? But I do not know if I need to augment the array until the callback executes.
2. Do I have to create another handle class that is used simply to hold this "unit" object array in a pass by reference scenario? Seems awfully clunky to me.
Thanks in advance!
Best Answer