How to use workspace variables in the App Designer of matlab?
22 ビュー (過去 30 日間)
古いコメントを表示
I have some structures in the matlab workspace. I would like to modify these structures inside "App Designer". This is done because I want the user to choose some parameters from the graphical interface so that then the struct is updated automatically. Are you able to help me? Because I tried calling uiopen in the App designer code, or in the matlab code. Then I tried to give the two struct as input arguments, but it does not work.
In few words the App Designer code does not recognise the structures I try to give as input. How can I solve this issue? Thank you.
2 件のコメント
Mohammad Sami
2020 年 1 月 16 日
In app designer you need to add a startup function. Change to code view and then click the App Input Arguments button.
You can then add any number of arguments you want to pass in to the app designer. Modify the startup function to do what you need to do with the inputs.
回答 (1 件)
Deepak
2024 年 12 月 10 日
To pass the structures in MATLAB App Designer, first add the arguments by clicking the "App Input Arguments" button in the Editor tab, which allows you to specify input arguments for the app. Mention the arguments that needs to pass to the startupFcn of the app.
Next, define properties in your app to hold these structures. In the startupFcn, assign the input arguments to the app properties. This setup ensures that the structures are accessible throughout the app.
Below is the App Designer code to achieve the same:
classdef myApp < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
% Other components here
end
properties (Access = private)
myStruct1 % Description
myStruct2 % Description
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app, myStruct1, myStruct2)
app.myStruct1 = myStruct1;
app.myStruct2 = myStruct2;
% Additional initialization code
end
end
% App initialization and construction
methods (Access = public)
% Construct app
function app = myApp(varargin)
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @(app)startupFcn(app, varargin{:}))
end
end
end
To run the app with structure arguments, we can use the below commands:
myStruct1 = struct('field1', value1);
myStruct2 = struct('fieldA', valueA);
app = myApp(myStruct1, myStruct2);
Please find attached the documentation of functions used for reference:
I hope this assists in resolving the issue.
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!