MATLAB: Assignin variables in a stand-alone application

assigninMATLAB Compilermccstandalone

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.

Best Answer

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.