MATLAB Answers

Standalone exe: how to change uigetdir to avoid the dependency of the path ?

12 views (last 30 days)
Molly on 3 Jun 2016
Commented: Molly on 7 Jun 2016
Hallo there,
I'm currently trying to built a standalone exe from my Matlab programm. Unfortunately I am using the path to different files/folders in my Matlab code and I know that this is not possible for a standalone exe. Is there an easy way to change this?
Thank you for your help!


Adam on 3 Jun 2016
Where do you want it to point to on an arbitrary machine? The problem is you don't know the folder structure on a different machine often so hard-coded paths are always dangerous and ones relative to e.g. the currently executing m-file will also land you in places you may not want to be in.
I have set up an environment variable that a user is prompted to set the first time they run on of our executables and this contains the user's 'Matlab Home' directory, then I can use this when I want to do things like saving files on the user's machine or taking a default directory for asking the user where to save files.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 3 Jun 2016
One thing to remember is that if you load() or imread() a file using a pathname that is not an absolute pathname, then in a standalone executable, the first place that it is going to check for the file is ctfroot(), and it will check there before looking at the MATLAB path. Therefore if you have read-only files and folders you can add them to the project and use them as-if they are in your current directory. If you need to write temporary files use tempdir() and tempname(); if you need to write permanent files then you start running into difficulty.


Show 2 older comments
Walter Roberson
Walter Roberson on 6 Jun 2016
Loading of .txt files should work, and loading of .mat files should work. load() of a .m file would be treated as load of a text file, which would look for a rectangle of text numbers, not for code.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!