How to get property of app object from classdef?
3 ビュー (過去 30 日間)
古いコメントを表示
Hello,
Typically, I set/get the app object property (text, value) within the code of the app.
I would like to do this stuff from a classdef. Could you please show me how to do it?
Thank you in advance.
0 件のコメント
回答 (1 件)
Deepak
2024 年 10 月 8 日
As I understand, you generally modify the properties of the app within the code of the app itself. Now, you want to know how to modify the properties of the app from a user-defined class in App Designer.
To accomplish this task, we must create a class using “classdef” in App Designer that will interact with the app. There should be “get” and “set” methods defined in the class to modify the app properties. Additionally, an instance of the class should be created in the “startupFcn” of the app to call the required class functions.
Below is the App Designer code for the same:
classdef AppController
properties
% Define any properties the class might need
end
methods
function obj = AppController()
% Constructor
end
function updateText(app, newText)
% Update the text property of the app
app.UIText.Text = newText;
end
function val = getValue(app)
% Get a value from the app
val = app.propertyName;
end
function setValue(app, newValue)
% Set a value in the app
app.propertyName = newValue;
end
end
end
function startupFcn(app)
% Create an instance of the class
controller = AppController();
% Update the text in the app
controller.updateText(app, 'Hello, World!');
% Get a value from the app
currentValue = controller.getValue(app);
disp(['Current Value: ', num2str(currentValue)]);
% Set a new value in the app
controller.setValue(app, 42);
end
Please find attached the documentation of “startupFcn” in App Designer for reference:
I hope you found this insightful.
0 件のコメント
参考
カテゴリ
Help Center および File 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!