GUI exe problem running external m file

Hi guys,
I am confronted with a probelm related to gui and exe. When I use run command in my GUI, it works well. But after I generated an exetutable program(exe), the run function report that the specified m file cannot be found. When I use a constant path to the run function. It reports that the m script cannot be executed. But the problem is that I can run it very well in guide. Are there anyone can help me?
Thanks a lot

回答(3 个)

Walter Roberson
Walter Roberson 2019-5-9
编辑:Walter Roberson 2019-5-9
You will never be able to use run() with MATLAB Compiler or Coder products. run() relies upon eval()
You will need to put the script onto your path and then refer to it by fixed name. It would then be compiled into the executable.
If the intent is to permit the user to provide executable matlab code then you will need to give up on that possibility.
If the need is for an initialization file that assigns only numeric constants or character vectors with no computation then I recommend looking in the file exchange for one of the programs that reads init files, which are data files rather than code.

7 个评论

Hi,
Thank you for your reply. I have solve this problem. It is possible to get the code inside the m files and then use eval to execute it.
Dear Tonghui,
I got a same problem here. The extrenal m. file can run well in guide but cannot in exe standalone program. Could you please let me know how did you solve this problem? Your kind concern is highly appreciated.
If the external file has fixed contents and fixed name, then you add it to the list of files to compile.
If the external file has to be edited by the user, and it contains MATLAB code, then you need to give up on the possibility: that situation would require run-time interpretation of the file, which cannot be done with MATLAB Compiler or MATLAB Coder.
If the external file has to be edited by the user, but it contains only simple numeric assignment statements (possibly of vectors) then there are File Exchange contributions that can read "init" files as data structures.
Hi Roberson,
Thanks for your answer. I am still trying to solve this problem as my intent is exactly to let the users input the script by themselves (as an external m. file). I will let you know if I manage to do it.
Hi Gideon,
I just read your comment. Because my task has been changed finally so I used gui instead the compiled exe. But I remember that I have solved the problem using eval instead of run. Hope that will solve your problem.
BR
Yours Zhang
There is no possibility that you will ever be permitted to use a user-provided matlab file with MATLAB Compiler or MATLAB Coder. NONE.
If users were permitted to run arbitrary matlab code then every free-to-distribute runtime license would be able to do nearly everything that a paid version could do.
The interface contract (Terms of Use) is that someone with an appropriate paid license builds something very specific that is not extensible, and in return they can compile and distribute that specialized thing with a royalty free license.
providing user ability to extend with matlab code would be a direct violation of the terms of use for the Compiler product.
Specialized code that does not duplicate matlab functionality: Yup, can (typically) be compiled and distributed free (or however much you want to charge)
Code that can be extended with user-provided matlab: forbidden by the Compiler license, end user must have full matlab license instead.

请先登录,再进行评论。

Hi Tonghui,
Thanks for your reply. May I ask is your code is a script with some specific outputs? Or just some input parameters and data? As my intent is to let the end-users to modify the file by themselves. My m. file is a simple script with some simple calculations and the results need to be callback into main compiled program. Do you think it is possible to achieve this by using "eval" function?
WR,
Gideon

5 个评论

Hi,
My previous mission is like this:
The 3rd user export a xml file including a state machine from other softwares and some m code inside it. My GUI should read these data and ran the code inside it.
BR
Yours Zhang
Hi Tonghui,
Thanks again for your reply. So actually your case is more complicated than mine as I just need to run some simple code in the m. file (I guess you also need to return the results after running the code). You are saying you replaced "run" function by "eval" function directly, right? Becasue "run" function cannot be compiled into a standalone exe. program.
Yours,
Gideon
Hi,
I remember I exchanged the code like that. Based on your situation, I have tried a sample.
M file has a name a.m and x=1 in it.
eval('a') in the GUi code.
Compile it like this mcc -m gui.m a.m
And then run the gui.exe using cmd code and it is working.
BR
Yours Zhang
Dear Tonghui,
Thanks for your reply. So you compiled "a" file into the program? Or end-users can change the "a" file as an independent external file (which means you did not compile it)? Actually I have tried to use "eval" replace "run" function, but it does not work. For example, I have an external file (named "Input.m"), the script is:
Sint=sin(t); Cost=cos(t);
The parameter "t" is given by main program. I use a pushbutton1 to load the "Input" file (with the full path and file name), and pushbutton2 to "run" it to get the value of Sint and Cost, and plot them. It works well. However, if I do not use the "run" function and use "eval" function instead in pushbutton2, I cannot obtain the Sint and Cost value (even in guide).
Yours,
Gideon
Hi,
If the script is certain you can compile it together with your main file. If you the end users only have access to the modification of t, I think you can edit as an input data by a text component in GUI and transfer it to your script.
if you want to use a standalone compiled gui without matlab to run the script, I do not think it is possible.
BR
Yours Zhang

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Application Deployment 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by