Add resources to compile .m

1 view (last 30 days)
Florian Segura
Florian Segura on 2 Dec 2019
Answered: Nicolas B. on 2 Dec 2019
Hello,
Here is my problem:
  • I have a pfile file.p, which call a data.mat file in .\resources\data.mat. I want to have a standalone application of that with .ctf file next to it. I use mcc to compile the both file:
mcc -W main:file -T compile:exe -v .\file.p -a '.\resources\data.mat'
  • But I have'nt found a way to make it work:
Error using load
'.\resources\data.mat' is not found in the current folder or on the MATLAB path, but exists in:
***********\Test_compilation
  • I can add manually a folder with the .mat file .\resources\data.mat next to my .exe, but is there a way to avoid that and "keep" a folder structure in the .exe ?
I use MATLAB 2017b with Windows 10. Matlab compiler of course.
Best,
Florian
EDIT:
after few test, this is working:
load('resources\data.mat')
And this is not working:
load('.\resources\data.mat')
But in my case, I have a pfile, so I can't modify the code. So I suppose that the data are called with a ".\".

Answers (1)

Nicolas B.
Nicolas B. on 2 Dec 2019
Personnally, I try to always access the files which are encapsulated into my applications without the path.
My advice:
  1. Use MATLAB/Simulink Projekt to create your workspace with all files you need in the path
  2. Replace all your relative path in your code with direct access to file (e.g. load data.mat)
  3. Compile your app
  4. To check what looks like your workspace once you start the compiled app, check the content of this folder:
C:\Users\<<your_username>>\AppData\Local\Temp\<<your_username>>\mcrCacheX.X\...
In this folder, you will find the exact workspace used by your app. You can then easily check that all files are included and what they have for path.

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!