using matlab compiler to read a .mat file at run time
17 views (last 30 days)
I want to compile a. m file, which included a load statement to load a .mat file, normally it seems this .mat file is then included in the compiled .exe file and cannot change (without recompilation). However, I would like the .exe file to load the .mat file at run time so I can change the contents of the .mat file with new data values. How do I do this?
Mike Croucher on 13 May 2022
Edited: Mike Croucher on 13 May 2022
You can tell the compiler to exclude things using an Exclude pragma A demo:
I created a .mat file as follows
myvar = 1;
Then create this code which I call loadAndShow.m
file = "data1.mat";
fprintf("The value of myvar is %d\n",myvar)
mcc -m loadAndShow.m
It will load the data1.mat file from the same directory as the .exe at runtime. Convince yourself of this by changing the contents of data1.mat.
More Answers (1)
Jan on 13 May 2022
Consider, that pwd is fragile. Any subfunction might change the current directory.
See here for a method to get the location of the exe file:
The ctfroot command might be useful also.