importing variables in compiled package

Hi all,
I have some matlab code from which I've extracted the important variables to a separate file that I called config.m...
%comment comment comment a = 1; %comment comment comment b = 2; ...
When I start up my code, this file is "sourced" by running config.m to load the parameters.
This has worked well for me while test/debugging. Now I want to compile the code, but keep the same configuration so I can tweak all the parameters for each run. One way around this I have found is to load my config file line by line, and use the eval function to get the variables into scope. Is this breaking any sort of license agreement if I distribute it? If so, are there any more valid ways to accomplish the same thing?

回答(3 个)

You are correct that it would be a license violation, as your executable would be providing the same functionality as the MATLAB command line by way of the user providing a config.m file that happened to include an input / eval loop.
You are responsible for ensuring that your program is secure against these kinds of hacks.
This does not rule out the use of eval (though it would not be recommended as there are clear alternatives such as dynamic structure fields), but it does mean that you have to scan the input for validity instead of blindly eval()'ing it. And if you are going to scan it for validity, you might as well use a data file.

5 个评论

What do you mean by "license violation"? You can't deploy an application with any m-file in it? I've seen many third party tools that are developed based on Matlab environment and included sorce .m files.
This is a situation in which the users are going to be providing the .m file; if security measures are not taken, then they would have access to MATLAB as a whole, in violation of the license term that the deployed package must not substantially provide functionality equivalent to MATLAB.
Thanks Walter,
can you point me to the right functions to use that wouldn't create a potential license violation? Ideally there is some sort of text file format that is load()-able for setting variables.
After some minimal thinking, I realize I could do the same as I was doing but filter out any lines that call functions. So I could throw out any lines that contain [, ], (, or ) and then there is no exposure to internal functions.
Note that some functions do not require arguments -- for example, "now" and "eps" .
I suspect you could reduce it down to checking whether the lines are of the form
name = numericvalue
and validate the name via ismember() against the set of names you specifically want to allow to be set.

请先登录,再进行评论。

I think you are doing perfectly fine regarding license or good practice. You can put your parameters in a M-script or a M-function. Just make sure you deal with the base workspace or function workspace properly.
Why don't you save the variables in a MAT file and just include the file when compiling it! Better way would be for your compiled application to have an interface that allows you to specify a MAT file( using uigetfile ). Then you could save multiple config params in separate MAT files and just choose the desired one at runtime

3 个评论

One of the benefits using M-file is that it is already a text file. It's easy to view and modify in non-Matlab environment.
Agreed, but then the correct way (in my opinion) should be to save it as a text file and use MATLAB file i/o to read the values. Saving it as a MATLAB file (M) doesn't seem like the right approach!
What sort of matlab i/o do you recommend? I'd like to keep the format of config.m similar to what I have above.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 MATLAB Compiler 的更多信息

标签

提问:

2011-6-13

Community Treasure Hunt

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

Start Hunting!

Translated by