MATLAB Answers


Problem running and editing Matlab scripts

Asked by Michael
on 21 Mar 2014
Latest activity Commented on by asiya
on 25 Jan 2016

Recently I began having a problem with Matlab where I'm unable to open and edit or run a script without getting an error message from Matlab editor saying,

"Error writing [File I'm trying to run/save] [Location of file on disk] (The process cannot access the file because it is being used by another process)".

This only happens after I've opened any saved file and edited it. After editing I cannot run or save the file without getting this error message. I can however start a new file and am able to both save it and run it multiple times without any problems. As soon as I close and reopen it again, I get the error message.

Is there something I accidentally changed? I have checked all the permissions in Windows and I should have no problem reading or writing files.

Matlab R2013a, Windows 7 Enterprise


Does fully closing down Matlab and reopening grant you access to the file again? I know it's stupid and you've already checked permissions in windows but since it is Enterprise have you checked the permissions of the files in question not just folder or user access?

I'm not having problems accessing the file or editing it, the problem occurs when I try to save or run the script after I've reopened it in the editor. Neither closing down Matlab nor restarting my computer fixes the problem. I checked and all the files have full permissions. I've also run Matlab as an administrator and this has no effect.

The only diagnostic I can think of is to open Task Manager to see if any other application could be open that might access ‘.m’ files. Does any other application associate with ‘.m’ files?

It may be time to ask Support for help.

Log in to comment.

2 Answers

Answer by Image Analyst
on 22 Mar 2014

What is the folder of the file? Is it under c:\Program Files? If so, you're out of luck. If not, what is the folder? There are other folders that you're supposed to be able to write into but sometimes can't (like c:\ProgramData) and others that you think you should be able to but can't (like c:\users).

Close MATLAB and type Ctrl-Shift-Esc. Click the process tab. Do you still see an instance of MATLAB running?

If you don't see it, then you need to download "unlocker" Install that and when you get a file collision it will tell you what's got the file locked and give you the opportunity to pry it's grip off your file. Then once you see what other process has locked your file then maybe you can do something to avoid it in the future.


It's not the code it's self causing the problem as it happens with any file I've re-opened, edited and attempted to save. I've tried creating a new file with no code and saving it, but as soon as I close and reopen, edit and attempt to save it again, I get the error message. All instances of Matlab shown on Unlocker happen at the same time when I open up any file. Could it be possible that Matlab is somehow preventing itself from saving files?

I've run out of ideas. You might have to call the Mathworks. They can set up a Webex session with you, and drive your computer, and solve it for you.

I had the same issue, while trying different options I found that command+0 helped me to get out of that freeze.

Log in to comment.

Answer by Michael
on 22 May 2014

I contacted the Mathworks service department and they advised me to upgrade to R2014a, which fixed the problem.


Log in to comment.

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

MATLAB Academy

New to MATLAB?

Learn MATLAB today!