Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: "Change directory" dialog box
Date: Thu, 8 Oct 2009 16:06:00 +0000 (UTC)
Organization: Universit&#228;t Heidelberg
Lines: 20
Message-ID: <hal2l8$25f$1@fred.mathworks.com>
References: <haidoe$mjn$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1255017960 2223 172.30.248.37 (8 Oct 2009 16:06:00 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 8 Oct 2009 16:06:00 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869888
Xref: news.mathworks.com comp.soft-sys.matlab:575978


Dear Andre!

> is there any way (other than adding a line of code in every file) to set the MATLAB preferences such that the default behavior for running m-files is to change the current directory to the directory where the file is located ?

This behaviour would be really confusing!
E.g. if you call FOPEN, the current directory would be matlabroot\toolboxmatlab\iofun\ and a file without a path is searched there. If you call FOPEN(WHICH(FileName)), the file is searched in matlabroot\toolbox\matlab\general at first...
I think, the frequent changes when calling "SIN(a + ABS(b))" would slow down Matlab completely: The + should change the current folder to the location of "plus.m" --- except if [b] is an object with an own PLUS operator...

I have a simple tool for situations like yours: A dialog has a popup, which activates different path sets. In fact, even the GUI is not needed:
  % Use ADDPATH/RMPATH to create one path;
  Path1 = path;
  % Use ADDPATH/RMPATH to create other path;
  Path2 = path;
Now you can toggle the paths, e.g.:
  path(Path1)
This will fail, if the current directory contains some of the called M-Files. So just CD to a neutral location.

A GUI for this has the advantage, that even the debugger break points can be stored/restored automatically in the callback, if the directory is changed.

Kind regards, Jan