MATLAB: App Designer: How to store multiple Checkbox values as array in property variable

app desigercheckboxproperty

Hello everybody,
I have an App with many Checkboxes, e.g.
app.1CheckBox app.2CheckBox app.3CheckBox
Now I would like to have an array storing the values of these checkboxes:
checkbox_states = [app.1CheckBox.Value,app.2CheckBox.Value,app.3CheckBox.Value]
Since I want to use checkbox_states for many different callback functions, I was wondering if I could add this variable as a public property? However this code does not seem to work:
properties (Access = public)
checkbox_states = [app.1CheckBox.Value,app.2CheckBox.Value,app.3CheckBox.Value]
end
Do I have to add this code in every callback function to be able to pass this array to the functions or is there another way of having this array always updated with the current checkbox values?
Thank you.

Best Answer

app.checkboxes = [app.1CheckBox, app.2CheckBox, app.3CheckBox];
in an initalisation function should work to store the checkboxes themselves (untested though - it works for general objects, I haven't tried with appdesigner graphics objects), then
[ app.checkboxes.Value ]
should give you the array of values at any time. Storing an array of the values is a bad idea as it will not automatically update so yes you would have to update it in every callback which would be rather pointless.
You can initialise in a few different ways, e.g.
You can do a 2nd phase initialisation with a public
function initialise( obj )
...
end
if you want, or you could create a static function to create your object which will call the constructor and then do any other stuff that you would normally do in the constructor, e.g.
methods( static, Access = public )
function obj = create( )
obj = MyApp( );
obj.checkboxes = [app.1CheckBox, app.2CheckBox, app.3CheckBox];
end
end