How do I associate files with a specific compiled App Designer application on Windows?

In most applications there are two ways you can open a file:
1. Open the application and then select the proper file. (ex. Open Microsoft Word and then select test.docx)
2. Open the file and it opens in the proper application. (ex. Open test.docx and it automatically opens in word)
I would like the same behavior in my compiled App Designer application, SampleApp.exe. I am able to use the first method, but I am unsure how to do the second.
The application should take in data files that are formatted in a particular way. Then I am just renaming them as .SampleApp files. For example I save testdata1.mat as testdata1.SampleApp.
When I double click on testdata1.SampleApp, I want MATLAB to open SampleApp.exe with testdata1 loaded in. I have already associated .SampleApp files to open SampleApp.exe, but I am unable to get the data loaded in the application.
How can I get the testdata1.SampleApp file to open the application with the testdata1 loaded in?

 Accepted Answer

In Windows, this can be done by including inputs into the application. The input will automatically be the name of the file selected and when no file is selected, the user can be prompted to select one.
Add an input to your application by going to "Code View" and the "Editor" tool-strip tab and selecting "App Input Arguments".
It is best to make the input argument "varargin", this way your app can be opened on its own or from the .SampleApp files.
For more information on "varargin", please see the following link:
Once your startupFcn is taking in input, you can simply call the following to load the variables into the app when they exist:
function startupFcn(app, varargin)
if ~isempty(varargin)
load(varargin{1}, '-mat');
else
[FileName, PathName] = uigetfile;
load([PathName FileName], '-mat');
end
end
Note: If you want to be able to access these variables outside the application's startupFcn, you will need to store them in the app.
Open your .SampleApp files with the EXE application and the data will load in. You can right click the .SampleApp file and select "Open with..." then navigate to SampleApp.exe.
Attached is an example which shows how this method can be used to load plotting data into an app. By opening testdata.SampleApp with a compiled SampleApp.exe, SampleApp.exe opens with the data from testdata.SampleApp plotted and labeled. If you open SampleApp.exe alone, you will receive an empty axes since no data was included.
Please note that this workflow is not yet supported on non-Windows platforms.

More Answers (0)

Categories

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

Products

Release

R2018b

Community Treasure Hunt

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

Start Hunting!