Assignin variables in a stand-alone application
5 次查看(过去 30 天)
显示 更早的评论
I am creating a stand-alone application using "mcc -mv foo.m" for my matlab code. In my code, I am using "assignin('base',var_name,var_value)" to assign value to variables. I read the variable values from a file and then assign those values to respective variables. What I am finding is that when I run the created executable, it actually remembers the old values that I had used during development/testing. How is it possible? Does mcc include workspace variables and their values at the time of creating stand-alone executables and does not override their values by assignin? I am currently using Matlab 2017a. My code has worked fine with 2014a in the past. I am using Matlab on Linux.
0 个评论
采纳的回答
Walter Roberson
2018-9-8
However, when you have a load() of statically named .mat file, then the .mat file is included in the archive, and that will be the file that is read from unless you take specific steps to read from a different file. In particular, if you load() a .mat then the current directory of the user running the executable will not be examined for the .mat file.
The current directory of a compiled executable is not going to be the user's directory unless you take care to figure out where the user's directory is and cd to there (such as by examining the HOME environment variable.) Furthermore when you load() from a file name with no path given, MATLAB always looks in the archive for the file first: to disable that you need to give the path at load() time.
6 个评论
Walter Roberson
2018-9-8
Right. And most of the time "current directory" in a compiled archive is not where you think it is.
If you hardcode a cd to a particular directory like
cd('C:\Program Files\Tiwariware\Megaosh')
then you have the problem that the user might have installed somewhere else or that the local drive might be reserved by IT for the operating system and all user files might have to go on a network drive.
You might want to look at https://www.mathworks.com/matlabcentral/fileexchange/15885-get-user-home-directory
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!