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

19 views (last 30 days)
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.
  4 Comments
Adam
Adam on 31 Jul 2017
Hmm, yes, I forgot App designer is so stupid! 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
Yangfan Peng
Yangfan Peng on 31 Jul 2017
Edited: Yangfan Peng on 31 Jul 2017
I have included it in the StartupFcn and it works now, thanks! :)
Because you commented on my question, I can not accept your answer...

Sign in to comment.

Accepted Answer

Adam
Adam on 31 Jul 2017
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

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!