How to use workspace variables in the App Designer of matlab?
    9 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
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 Commenti
  Mohammad Sami
      
 il 16 Gen 2020
				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.
Risposte (1)
  Deepak
 il 10 Dic 2024
        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 Commenti
Vedere anche
Categorie
				Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange
			
	Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



