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

조회 수: 7 (최근 30일)
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
Adam
Adam 2017년 7월 31일
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 2017년 7월 31일
편집: Yangfan Peng 2017년 7월 31일
I have included it in the StartupFcn and it works now, thanks! :)
Because you commented on my question, I can not accept your answer...

댓글을 달려면 로그인하십시오.

채택된 답변

Adam
Adam 2017년 7월 31일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by