How to assign the value of an ui.control element to a variable in public property in App Designer

6 次查看(过去 30 天)
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.

采纳的回答

Mario Malic
Mario Malic 2021-5-24
编辑:Mario Malic 2021-5-24
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 个)

类别

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