MATLAB Answers

I used "uigetdir" in a GUI and want that folder window starts from directory of m file of the GUI. I changed current directory by mfilepath and cd commands but it did not work. How can achieve this?

4 views (last 30 days)
Gökay Tunç
Gökay Tunç on 30 Jul 2015
Answered: Walter Roberson on 30 Jul 2015
I used following script to obtain m file directory and to change current directory:
p = mfilename('fullpath');
s = find(p=='\');
filePath = p(1:s(end)-1);
cd(filePath);
s and filePath part is for obtaining the folder directory, not for m file address.
Then I used uigetdir(cd). It works on R2013b but not on R2011b. How can I overcome this situation for R2011b?

  0 Comments

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 30 Jul 2015
p = mfilename('fullpath');
[filePath, filename, ext] = fileparts(p);
user_selected_dir = uigetdir(filePath);

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by