Passing data into and out of an App

39 views (last 30 days)
Chris
Chris on 12 Aug 2019
Answered: Subhadeep Koley on 20 Aug 2019
I am new to Apps and would like to make sure I am clear on how to it is best to get data into and out of an App.
I need to be able to run my App from an mfile and pass it input and get outputs from it. Running my App from the "App" tab is secondary, where IO can be done explicitly with user input this is not a problem.
You can run a packaged App from code via
matlab.apputil.run('PlotDataAPP')
But this does not seem to let you pass data directly in or get data directly out.
Else it looks like you can run the .mlapp directly from code with input arguemts via startupFcn(). But I dont see a good way to extract data from the App back into the mfiles workspace other than use of a global variable or the 'base' workspace.
% From within my mfile code
global myOutputData
foo = myApp(myInputData); % myOutputData is also a global within a function in myApp
uiwait(foo.UIFigure); % pause mfile execution to let the user do things in myApp
plot(myOutputData) % do something with mOutputData that was set within myApp
The above code works but seems very sloppy.
Could I use global varialbes to get data into and out of a packaged App where my mfile can then use matlab.apputil.run?
Is there a better way to do data IO? Reading/writing mat files is not an option - cant risk propriatary data being saved in odd places. Passing data through the 'base' workspace could be done but seems about a slopy as using globals.
Is there any real difference between running the packaged app and running the .mlapp?

Answers (1)

Subhadeep Koley
Subhadeep Koley on 20 Aug 2019
Since you prefer not to use global declaration or importing variable from Base Workspace, you can use properties option of the App Designer. properties is the best way to share data within an app because properties are accessible to all functions and callbacks in an app.
Refer the documentation here.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!