Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Current directory

Subject: Current directory

From: tinne123

Date: 18 May, 2010 15:59:04

Message: 1 of 9

Hi folks,

I am puzzled by the behaviour of current directory in R2008b. Please do you know the way to ensure that only one path is active and the directory does not change?

Under Preferences / Current Directory I cleared the history and set the number of recent directories for saving to 1, the one I kept in the Current directory list (top center of the console). Despite this it happens that in next sessions more directories appear in the list again. It is causing troubles while I am working with .mat files.

Does please anybody know how to fix this? Many thanks for advise!!

Subject: Current directory

From: Jan Simon

Date: 18 May, 2010 22:13:04

Message: 2 of 9

Dear tinne123!

> I am puzzled by the behaviour of current directory in R2008b. Please do you know the way to ensure that only one path is active and the directory does not change?
>
> Under Preferences / Current Directory I cleared the history and set the number of recent directories for saving to 1, the one I kept in the Current directory list (top center of the console). Despite this it happens that in next sessions more directories appear in the list again. It is causing troubles while I am working with .mat files.

The current directory is a single folder only. The list of formerly accessed "current" directories does not influence the reading of MAT files. So it would be necessary, that you describe your problems with some details.

Jan

Subject: Current directory

From: ImageAnalyst

Date: 19 May, 2010 01:03:25

Message: 3 of 9

What do you mean by active? Only one path is active for saving stuff
- that is the current folder (unless you specifically give the whole
path to the function that's doing the saving). Now, there is a search
path, which is different than the current folder. If it's trying to
find something it looks in the current folder first, then if it can't
find it there it goes into the search path. If you want to get rid of
that you'll have to use rmpath() I suppose. Put
rmpath(genpath(path)) in your startup.m file to erase the search
path. You'll have to supply the starting folder. I'm not really sure
where the search path is initially defined. Maybe it's already in
path, or maybe it's in some other variable - I'm not sure unless I go
researching it - but once you find it, stick it in rmpath(genpath())
to try to get rid of it. You might also want to call savepath.

Subject: Current directory

From: tinne123

Date: 19 May, 2010 16:04:05

Message: 4 of 9

Hi Jan Simon and ImageAnalyst,

thanks for your replies. I checked out the rmpath command. It should have the same effect as managing the paths through Set path. I am sorry if I used wrong vocabulary in my post. I will try it again from the beginning, okey?

I have troubles with the Current Directory (as is displayed in R2008b above the Command Window in the default desktop layout). More specifically, I wish to use only one directory, be it C:\Program Files\MATLAB\R2008b\work, a folder I created.

What I instead have are two directories in the above mentioned list, be it C:\Documents and Settings\Username\Desktop (and originally, there were some more. Matlab appears to switch from my preferred directory to this one at its start and also while working, so that I have to check the active directory before running .m files. The consequences in practice look like that I erroneously saved a couple of .mat files to PC Desktop...



The list of things I have tried to avoid this:
1. Setting my desired directory as the default path under Set path and deleting the undesired paths. Alternative would be using the rmpath command and alike, as far I understood. But I doubt it has much to do with this. Please note, that C:\Documents and Settings\Username\Desktop is not included under Set path (and I even think it never was.) Yet it persists in the list to Current Directory line.

2. Under Preferences / Current Directory I cleared the history and set the number of directories to save to 1. Alternative is to adjust the cwdhistory.m manually in the preferences folder [the tip from Matlab Technical support]. I checked both.

Neither of these steps prevents C:\Documents and Settings\Username\Desktop to appear in the list to Current Directory, so if I forget to look before running an .m code, mess will happen again.


It is such a stupid thing, but I don't know the help. I just post this here, paralelly to further communication with the Technical Support. Maybe someone experienced the same problem with R2008b. Many thanks!!

Subject: Current directory

From: Steven Lord

Date: 19 May, 2010 17:08:05

Message: 5 of 9


"tinne123 " <nastanova@yahoo.co.uk> wrote in message
news:ht125l$2t7$1@fred.mathworks.com...
> Hi Jan Simon and ImageAnalyst,
>
> thanks for your replies. I checked out the rmpath command. It should have
> the same effect as managing the paths through Set path. I am sorry if I
> used wrong vocabulary in my post. I will try it again from the beginning,
> okey?
>
> I have troubles with the Current Directory (as is displayed in R2008b
> above the Command Window in the default desktop layout). More
> specifically, I wish to use only one directory, be it C:\Program
> Files\MATLAB\R2008b\work, a folder I created.
>
> What I instead have are two directories in the above mentioned list, be it
> C:\Documents and Settings\Username\Desktop (and originally, there were
> some more. Matlab appears to switch from my preferred directory to this
> one at its start and also while working, so that I have to check the
> active directory before running .m files. The consequences in practice
> look like that I erroneously saved a couple of .mat files to PC Desktop...

I wouldn't expect MATLAB to spontaneously change your Current Directory.
Can you check and make sure that you haven't changed the Start In property
of the shortcut from which you started MATLAB and that you do NOT have a
file named startup.m in the directory in which MATLAB initially starts up?
If you do have a startup.m file, does it CD to the Desktop directory?

> The list of things I have tried to avoid this:
> 1. Setting my desired directory as the default path under Set path and
> deleting the undesired paths. Alternative would be using the rmpath
> command and alike, as far I understood. But I doubt it has much to do with
> this. Please note, that C:\Documents and Settings\Username\Desktop is not
> included under Set path (and I even think it never was.) Yet it persists
> in the list to Current Directory line.

The MATLAB path (which is what you're changing with Set Path) has nothing
really to do with the current directory.

> 2. Under Preferences / Current Directory I cleared the history and set the
> number of directories to save to 1. Alternative is to adjust the
> cwdhistory.m manually in the preferences folder [the tip from Matlab
> Technical support]. I checked both.

Changing the history (either contents or size) shouldn't affect whether or
not MATLAB changes directory, just how many directories are recorded.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Current directory

From: tinne123

Date: 19 May, 2010 18:30:43

Message: 6 of 9

Hi Steve Lord,

thanks for your message. Thanks also for explaining me the proper vocabulary, I hope I won't make any typos anymore.

> I wouldn't expect MATLAB to spontaneously change your Current Directory.
> Can you check and make sure that you haven't changed the Start In property
> of the shortcut from which you started MATLAB and that you do NOT have a
> file named startup.m in the directory in which MATLAB initially starts up?
> If you do have a startup.m file, does it CD to the Desktop directory?
>

I would not say it happended 100%-ly spontaneously. As explained, I created the folder work myself, in C:\Program Files\MATLAB\R2008b\work as I was used to it under R2006a. I had no idea that in R2008b I need to adjust some starts ins / starts ups..? whatever it is?

I think, the Current Directory created upon installation was something like User\My documents\MATLAB. That one I physically destroyed as a folder (and removed from paths, too, under Set path.)

I do not quite see why Matlab created C:\Documents and Settings\Username\Desktop. Maybe because I once saved a .m file to PC Desktop (although before creating work I think), so Matlab just tried to find a possible directory? The next directory it then also added to the list was "work", although now it appears to have problems to work spontaneously, unless I do not open an .m file saved to work.

I removed the one .m file from the PC Desktop and there is no startup.m file, nor anything else in common with Matlab, except for the Matlab Short Cut bar. The Current Directory Matlab sessions start with is the PC desktop, C:\Documents and Settings\Username\Desktop.

Thanks for helping!

Subject: Current directory

From: Jan Simon

Date: 19 May, 2010 19:55:18

Message: 7 of 9

Dear Tinne123!

> I would not say it happended 100%-ly spontaneously. As explained, I created the folder work myself, in C:\Program Files\MATLAB\R2008b\work as I was used to it under R2006a. I had no idea that in R2008b I need to adjust some starts ins / starts ups..? whatever it is?
>
> I think, the Current Directory created upon installation was something like User\My documents\MATLAB. That one I physically destroyed as a folder (and removed from paths, too, under Set path.)

When Matlab starts it has to decide for a current folder. Matlab 2008b considers mutli-user environments - if all users would start in "C:\Program Files\MATLAB\R2008b\work", there might be interferences. Therefore Matlab 2008b uses a folder depending on the currently active user. Because you have deleted this folder and removed it from the Matlab path, Matlab has to guess, which folder is apropriate. And according to the limited intelligence of Matlab, it decides for the desktop folder.

A possible solution: Create the original startup folder again and restore the original Matlab path. Then create the file "startup.m" in this directory and insert this line there:
  cd('D:\TheFolder\YouWouldLike\ToStartAndWork\In');
with the obvious mdofications.

Good luck, Jan

Subject: Current directory

From: ImageAnalyst

Date: 19 May, 2010 20:44:27

Message: 8 of 9

tinne:
Why don't you take a look at this closely related thread and see if
that solves your problem.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/282031#744834
-Image Analyst

Subject: Current directory

From: tinne123

Date: 19 May, 2010 21:34:06

Message: 9 of 9

Hi Guys,

thanks for your posts. To be sure, I prefer to assure myself I understand before I do someting as I saw in the ImageAnalyst post that Matlab knows to do worse than just choosing the PC Desktop.

So, putting it together...

>Then create the file "startup.m" in this directory and insert this line there:
> cd('D:\TheFolder\YouWouldLike\ToStartAndWork\In');
> with the obvious mdofications.

---------------------------------------------------------------------
Initially I had this in my startup.m file:
addpath(genpath('C:\Program Files\MATLAB\Work'));
cd 'C:\Program Files\MATLAB\work'

I then edited the startup.m file to put in take out the above lines
and put these in:
rmpath(genpath('C:\Program Files\MATLAB\Work'));
addpath(genpath('C:\Program Files\MATLAB\Work1'));
cd 'C:\Program Files\MATLAB\work1'
savepath;
I then saved it, and restarted MATLAB twice .
Once you have it working with no error messages, you can delete the
rmpath() command from your startup.m file if you want.
-----------------------------------------------------------------------

1.. My default folder (for the original current directory) does not exist anymore - shall I re-create it? If I do not re-create the original foder I am afraid the rmpath command would not be valid. Or may I just skip the line?

2.. At the moment, the existing startup.m file contents is this one:
% Force loading of Simulink or HG or something. See g401763.
close all force;
try
    bdclose('all');
end
clear all;

Can I just modify the startup.m file (where it normally resides) according to the steps above: rmphath(), addpath(), cd ' ', savepath.

3... Restart console twice.

Sorry that I ask so much, but I realized that one can get into trouble easily and I have respect. Many thanks for helping!!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us