Creating a standalone application with dynamic data objects

I have an application that processes input using data models that are in .mat files. I've added the models to the build using the -a flag; however, I'd like to let the user specify the models to use when they run the application. Ideally something like
./my_app data/folder/1 data/folder/2
where the inputs are the paths to the .mat files that get loaded using load(). Is it possible to specify the .mat files after the application has been compiled and distrubted, or does the Matlab Compiler require that the .mat files be added prior to compilation?

답변 (1개)

Walter Roberson
Walter Roberson 2014년 3월 17일
The compiler does not require that the .mat files be added prior to compilation. However, if you use
load(filename)
instead of
result = load(filename)
then you may run into problems with variables that are to be loaded into the workspace. It is best to not "poof" new variables into place using load() or evalin() or assignin() or eval()

댓글 수: 4

Sean
Sean 2014년 3월 17일
편집: Sean 2014년 3월 17일
Thanks for the reply. The .mat files are currently loaded and assigned to variables such as result = load(filename), which works fine in matlab. But when the standalone app is run, an error is thrown for attempting to access a non-existant member of a struct when I later try to use result.somemember.
As a debugging step, display fieldnames() of the structure right after the load(), and also use whos('-file','TheFileName') on the .mat file to see the variables saved in the file.
I get the following warning
Warning: Variable 'var' originally saved as a 'Object type' cannot be instantiated as an object and will be read in as a uint32.
And then fieldnames fails, as it's called on a uint32.
After doing some research, it seems like the classdef needs to be included in the compilation either using the %#function pragma, or somehow including the classdef (not sure I have this) in the compilation. However, this is what I want to avoid--I'd like people to be able to run the app with their own models.
Are you trying to import objects from the .mat file where you do not care what the actual objects are as long as they have some particular set of methods that your exe applies to them? If so then I do not know if it is possible to support that.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

질문:

2014년 3월 17일

댓글:

2014년 3월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by