Got Questions? Get Answers.
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:
m-file shadows itself? Confused about error

Subject: m-file shadows itself? Confused about error

From: Jeff Evans

Date: 29 Jun, 2009 13:25:03

Message: 1 of 9

Hello all,

Beginning yesterday I have been receiving an error when I run two scripts (using F5 from the editor) called randomregression.m and checkSummerDDfcn.m. Both are in the same folder, which is on the search path. There are no files in my file system with conflicting names. They ran without error for several weeks previously.

The error for the first file reads:
"MATLAB cannot run this file because C:\...Refit DD function\randomregression.m shadows it in the working directory. To run this file you must change the MATLAB current directory."

The first two lines of each script are:
clear all; close all;
cd('C:\...Refit DD function\');

Commenting out the cd line does not help.
Deleting the branch of the path containing this directory and resetting it I was able to run the second function once without the error, but then it reappeared. Repeating this action was not effective.

I moved one of the files up one folder level, ran it once without error, but the error reappeared the second time I ran it from this directory. I put it back in the original folder, ran it once without error, but then the error reappeared. Same thing.

Any idea what's going on here?

Subject: m-file shadows itself? Confused about error

From: Steven Lord

Date: 29 Jun, 2009 13:33:00

Message: 2 of 9


"Jeff Evans" <evansj18.noSpamPlease@msu.edu> wrote in message
news:h2afbf$cu8$1@fred.mathworks.com...
> Hello all,
>
> Beginning yesterday I have been receiving an error when I run two scripts
> (using F5 from the editor) called randomregression.m and
> checkSummerDDfcn.m. Both are in the same folder, which is on the search
> path. There are no files in my file system with conflicting names. They
> ran without error for several weeks previously.
>
> The error for the first file reads:
> "MATLAB cannot run this file because C:\...Refit DD
> function\randomregression.m shadows it in the working directory. To run
> this file you must change the MATLAB current directory."
>
> The first two lines of each script are:
> clear all; close all;
> cd('C:\...Refit DD function\');
>
> Commenting out the cd line does not help.
> Deleting the branch of the path containing this directory and resetting it
> I was able to run the second function once without the error, but then it
> reappeared. Repeating this action was not effective.
>
> I moved one of the files up one folder level, ran it once without error,
> but the error reappeared the second time I ran it from this directory. I
> put it back in the original folder, ran it once without error, but then
> the error reappeared. Same thing.
>
> Any idea what's going on here?

Do you add the directory containing the scripts to the path using ADDPATH
inside one of the scripts? If so, try commenting out that line or those
lines in your scripts and see if that resolves the problem.

--
Steve Lord
slord@mathworks.com

Subject: m-file shadows itself? Confused about error

From: Jeff Evans

Date: 29 Jun, 2009 13:38:01

Message: 3 of 9

Thanks Steve,

No, I added it via "Set Path" in the File menu.

Jeff

Subject: m-file shadows itself? Confused about error

From: Jeff Evans

Date: 29 Jun, 2009 13:40:18

Message: 4 of 9

Addendum:

I now see that the error is not specific to that one directory. It appears when I run scripts from other directories as well.

Jeff

Subject: m-file shadows itself? Confused about error

From: Warwick

Date: 22 Nov, 2009 00:49:02

Message: 5 of 9

"Jeff Evans" <evansj18.noSpamPlease@msu.edu> wrote in message <h2ag82$ca7$1@fred.mathworks.com>...
> Addendum:
>
> I now see that the error is not specific to that one directory. It appears when I run scripts from other directories as well.
>
> Jeff

I have similar problems. Everything was fine for a year or so. Now nearly every script repeatedly requires me to acknowledge this warning and click on "change Directory".

I haven't been able to figure out how to fix it. I'm using a Mac and it has only been since I upgraded to Snow Leopard - that may just coincidence, of course.

Warwick

Subject: m-file shadows itself? Confused about error

From: Mark

Date: 18 Oct, 2011 15:42:25

Message: 6 of 9

I was able to solve this by closing and reopening the .m files.

"Warwick" wrote in message <hea1pu$pg3$1@fred.mathworks.com>...
> "Jeff Evans" <evansj18.noSpamPlease@msu.edu> wrote in message <h2ag82$ca7$1@fred.mathworks.com>...
> > Addendum:
> >
> > I now see that the error is not specific to that one directory. It appears when I run scripts from other directories as well.
> >
> > Jeff
>
> I have similar problems. Everything was fine for a year or so. Now nearly every script repeatedly requires me to acknowledge this warning and click on "change Directory".
>
> I haven't been able to figure out how to fix it. I'm using a Mac and it has only been since I upgraded to Snow Leopard - that may just coincidence, of course.
>
> Warwick

Subject: m-file shadows itself? Confused about error

From: Eric Pheterson

Date: 29 Oct, 2011 20:16:14

Message: 7 of 9

Same solution as Mark:

SOLUTION

1. Close and re-open the .m file.

Very annoying error, especially because every time you run you're changing the folder to the same folder, in effect doing nothing. Thanks

Subject: m-file shadows itself? Confused about error

From: Egor

Date: 25 Nov, 2012 19:09:09

Message: 8 of 9

"Eric Pheterson" <epheterson@gmail.com> wrote in message <j8hmue$dnh$1@newscl01ah.mathworks.com>...
> Same solution as Mark:
>
> SOLUTION
>
> 1. Close and re-open the .m file.
>
> Very annoying error, especially because every time you run you're changing the folder to the same folder, in effect doing nothing. Thanks

Same here for Mac on Mounted Lion. thanks

Subject: m-file shadows itself? Confused about error

From: Rajith

Date: 15 Feb, 2013 06:36:16

Message: 9 of 9

"Egor" wrote in message <k8tqcl$c66$1@newscl01ah.mathworks.com>...
> "Eric Pheterson" <epheterson@gmail.com> wrote in message <j8hmue$dnh$1@newscl01ah.mathworks.com>...
> > Same solution as Mark:
> >
> > SOLUTION
> >
> > 1. Close and re-open the .m file.
> >
> > Very annoying error, especially because every time you run you're changing the folder to the same folder, in effect doing nothing. Thanks
>
> Same here for Mac on Mounted Lion. thanks

HERE IS THE SOLUTION FOR THIS:
-----------------------------------------------------
The name of the mdl and the .m file are probably same. If so, rename the .m file

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