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

7 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Mario Malic
Mario Malic am 24 Mai 2021
Bearbeitet: Mario Malic am 24 Mai 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.

Weitere Antworten (0)

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by