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
2019-5-9
编辑:Walter Roberson
2019-5-9
0 个投票
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 个评论
Tonghui Zhang
2019-5-9
Gideon Tang
2020-6-4
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.
Walter Roberson
2020-6-4
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.
Gideon Tang
2020-6-5
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.
Tonghui Zhang
2020-6-5
Walter Roberson
2020-6-5
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.
Gideon Tang
2020-6-5
Thanks Walter
Gideon Tang
2020-6-5
0 个投票
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 个评论
Tonghui Zhang
2020-6-5
Gideon Tang
2020-6-5
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
Tonghui Zhang
2020-6-5
Gideon Tang
2020-6-5
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
Tonghui Zhang
2020-6-5
类别
在 帮助中心 和 File Exchange 中查找有关 Application Deployment 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!