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:
How to change startup directory in Matlab 7.5

Subject: How to change startup directory in Matlab 7.5

From: Irian O

Date: 8 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: 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: 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: 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: 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

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