matlab standalone application default directory is cache directory

I have developed an application on Mac OSX 10.9.5 which requires reading and writing files to directory relative to current directory. When i built a standalone application i find that the current directory is some cache directory. so all read and writes are relative to that directly. How do i set working directory? Can I have an interface to define the directories.

 Accepted Answer

OS-X graphics apps do not really have a "current" directory at start time, in useful sense. They are started from the desktop or one of the explorer windows, and so are independent of any "current" directory that user might have -- the user might have a number of different "current" directories in different windows the user has open.
OS-X non-graphics apps that are started from the command line might have a meaningful "current" directory, since they would have to be started from a shell: is that a situation relevant to you?

2 Comments

Thanks Walter for your response. In that case I would want to read and write files that are relative to the directory where the application is installed. Also if there is a way of setting the working directory in my startup program
Notice the guidance,
A compiled application behaves more consistently if it:
  • Does not change any path during execution.
  • Uses relative paths (or anchors paths to a known root via the matlabroot or ctfroot functions).
  • Avoids accessing or changing the current directory.
I would suggest, then, that if you do put something in startup then it should be a variable indicating which directory to use (for something) but do not actually cd() to there. And remember that when other people use the application their startup.m is not going to be looked at, so it is not clear that putting code into startup.m is a good idea compared to putting it into a clearly labeled initialization file that is compiled into the application.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!