フィルターのクリア

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

3 ビュー (過去 30 日間)
Yangfan Peng
Yangfan Peng 2017 年 7 月 28 日
回答済み: Adam 2017 年 7 月 31 日
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 Center および File ExchangeGraphics Object Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by