Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: How to change startup directory in Matlab 7.5

Subject: How to change startup directory in Matlab 7.5

From: Irian O

Date: 08 Mar, 2008 22:31:03

Message: 1 of 5

Hi everyone,

I have been the following commands in one of my codes:

!matlab -nosplash -r myscript &

This starts a new instance of Matlab and runs the script
"myscript.m". The problem is that when the new Matlab
window opens it starts in the default main Matlab directory
instead on the current or working directory when I ran the
"!matlab .... command". Does anyone know how I can change
it so it remembers in which directory the previous working
directory?

Thanks!

Subject: Re: How to change startup directory in Matlab 7.5

From: Christophe Boudrie

Date: 16 Mar, 2008 17:50:19

Message: 2 of 5

"Irian O" <merlingt1@yahoo.com> wrote in message <fqv437
$s8b$1@fred.mathworks.com>...
> Hi everyone,
>
> I have been the following commands in one of my codes:
>
> !matlab -nosplash -r myscript &
>
> This starts a new instance of Matlab and runs the script
> "myscript.m". The problem is that when the new Matlab
> window opens it starts in the default main Matlab
directory
> instead on the current or working directory when I ran
the
> "!matlab .... command". Does anyone know how I can change
> it so it remembers in which directory the previous
working
> directory?
>
> Thanks!

Hi, you may simply send the command "cd" for cd(pwd) "pwd"
is current directory when you invoke the new matlab window:
! matlab -r cd(pwd),my_script...

Another way is to specify the full path of the file you
which to run:
!matlab -r run('C:\my_folder\my_script.m')

Finally, if you whish to control matlab when ran, you can
use matlab as an automation server: h = actxserver
('matlab.application'), see matlab help for more details.

regards,
chris

Subject: Re: How to change startup directory in Matlab 7.5

From: Vihang Patil

Date: 17 Mar, 2008 09:16:04

Message: 3 of 5

"Irian O" <merlingt1@yahoo.com> wrote in message <fqv437
$s8b$1@fred.mathworks.com>...
> Hi everyone,
>
> I have been the following commands in one of my codes:
>
> !matlab -nosplash -r myscript &
>
> This starts a new instance of Matlab and runs the script
> "myscript.m". The problem is that when the new Matlab
> window opens it starts in the default main Matlab
directory
> instead on the current or working directory when I ran
the
> "!matlab .... command". Does anyone know how I can
change
> it so it remembers in which directory the previous
working
> directory?
>

This is what you need
doc startup
doc finish
doc pwd

You will need to code your finish.m file in such a way
that when you close/exit matlab, it will execute the code
in it which has the reference to the present working
directory or pwd and then it outputs that string of the
pwd to startup.m file
In your startup file, your code should be something like
this
cd('<path string generated from finish.m>')
HTH
Vihang

Subject: Re: How to change startup directory in Matlab 7.5

From: Irian O

Date: 17 Mar, 2008 14:40:25

Message: 4 of 5

Thank you all,

I got it working by editing my startup.m everytime with the
directory "cd('mydirectory')" which I wish to be in before
I launch a new Matlab window. It is kind of a nuisance
because with Matlab 7.0 I never had to do this and it
automatically knew the last directory I was in. I am not
sure if it is something that changed or if it is a program
setting that I am missing.

Cheers!
Irian

"Vihang Patil" <vihang_patil@yahoo.com> wrote in message
<frlcsk$3lo$1@fred.mathworks.com>...
> "Irian O" <merlingt1@yahoo.com> wrote in message <fqv437
> $s8b$1@fred.mathworks.com>...
> > Hi everyone,
> >
> > I have been the following commands in one of my codes:
> >
> > !matlab -nosplash -r myscript &
> >
> > This starts a new instance of Matlab and runs the
script
> > "myscript.m". The problem is that when the new Matlab
> > window opens it starts in the default main Matlab
> directory
> > instead on the current or working directory when I ran
> the
> > "!matlab .... command". Does anyone know how I can
> change
> > it so it remembers in which directory the previous
> working
> > directory?
> >
>
> This is what you need
> doc startup
> doc finish
> doc pwd
>
> You will need to code your finish.m file in such a way
> that when you close/exit matlab, it will execute the code
> in it which has the reference to the present working
> directory or pwd and then it outputs that string of the
> pwd to startup.m file
> In your startup file, your code should be something like
> this
> cd('<path string generated from finish.m>')
> HTH
> Vihang
>

Subject: Re: How to change startup directory in Matlab 7.5

From: Vihang Patil

Date: 18 Mar, 2008 05:16:02

Message: 5 of 5

"Irian O" <merlingt1@yahoo.com> wrote in message
<frlvsp$dit$1@fred.mathworks.com>...
> Thank you all,
>
> I got it working by editing my startup.m everytime with the
> directory "cd('mydirectory')" which I wish to be in before
> I launch a new Matlab window. It is kind of a nuisance
> because with Matlab 7.0 I never had to do this and it
> automatically knew the last directory I was in. I am not
> sure if it is something that changed or if it is a program
> setting that I am missing.
>
> Cheers!
> Irian
>
You can try this simple utility found here
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=19239&objectType=file

or

http://tinyurl.com/3xwbbm

HTH
Vihang

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
matlab 75 startup directory Irian O 08 Mar, 2008 17:34:57
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics