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.

采纳的回答

Walter Roberson
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 个评论
Santosh Tiwari
Santosh Tiwari 2018-9-8
OK. Thanks for the explanation. This is probably the most likely cause. I have not specified the path in the fopen(), just the file name. I assumed fopen() will first lookup in the current directory; but you are telling me that it will check ctfroot() first. For a standalone executable, this is probably the archive and mcc pulls in the file if it finds it during compilation.
Walter Roberson
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by