How to assign the value of an ui.control element to a variable in public property in App Designer
7 views (last 30 days)
Show older comments
Hi,
in my callbacks I can simply say:
% Button pushed function: StartButton
function StartButtonPushed(app, event)
A = app.Spinner1.Value;
But now I need to define A in public or private property to get access from all callbacks. But when I write:
properties (Access = public)
Property % Description
A = app.Spinner1.Value;
I get this Error:
Invalid default value for property 'A' in class 'Example':
Unable to resolve the name app.Spinner1.Value.
0 Comments
Accepted Answer
Mario Malic
on 24 May 2021
Edited: Mario Malic
on 24 May 2021
Hey,
The public access to the property or the method means that if you start your app from the outside, from the Command Window like this, you will be able to get property named "Property" as defined in that block.
app = NameOfApp;
app.Property % ask what's inside Property
So, what you need is to reference the property of the app correctly.
properties (Access = public)
Property % Description
A
end
Notice, that your app has now property A, and you index into it like this
app.A
So, you can assign a value to property like this
% Button pushed function: StartButton
function StartButtonPushed(app, event)
app.A = app.Spinner1.Value;
end
That should be it, before asking for similar questions, take a look at tutorials here and introductory apps in the App Designer, and there are plenty of questions in MATLAB Answers.
0 Comments
More Answers (0)
See Also
Categories
Find more on Develop Apps Using App Designer 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!