MATLAB Answers


MATLAB will not start up after several crashes due to a bad MEX file

Asked by AP
on 25 Oct 2012
Latest activity Commented on by Rahul Choure
on 18 Nov 2015

Dear All,

I was debugging my MEX file because of a bug in the code. Each time the code runs, MATLAB crashes. I think it was after 3-4 times crashing that MATLAB did not start up at all. MATLAB splash screen loads and will disappear after a second but MATLAB interface does not start. Even restarting the computer does not help. Does someone know why this happens? It's disappointing because I have a project due.

I am using MATLAB 2012b, Windows 7 x64, and Visual Studio 2008.





No products are associated with this question.

8 Answers

Answer by Andreas Goser
on 25 Oct 2012

You can try deleting (or better renaming so that you be reuse old prefences later) the preference directory. Find the matlab.prf file on your machine to find the directory.

When you rename the directory, you keep all old files and MATLAB created ne default one when starting.

  1 Comment

It works. Thanks Andres.

Answer by Michael Litvin
on 23 Mar 2013

I had the same exact problem. My solution:

  • Go to C:\Program Files\MATLAB\R2012b\sys\java\jre\win64
  • Rename 'jre' folder (the inner one, jre\win64\jre->jre\win64\jre_bck)
  • Install a newer version of JRE (I have 1.7.0_10 64bit)
  • Create a symbolic link from C:\Program Files\Java\jre7 to C:\Program Files\MATLAB\R2012b\sys\java\jre\win64\jre

That's it.


Answer by Jonathan Currie on 4 May 2013

I develop a lot of MEX files (and thus crashes happen fairly frequently) and had this issue on every version of MATLAB (32bit and 64bit) since about 2009a (when I first started developing). I often go through cycles of uninstalling and re-installing MATLAB until eventually it works again. Sometimes reinstalling the JRE helps, sometimes not.

This is a real pain and it would be good if MathWorks could sort it out. Currently fighting 2013a 64bit and up to 5th reinstall, wiping the AppData folder each time and reinstalled JRE a number of times...


Answer by Jan Berling
on 29 Mar 2014

I had the same problem.

I removed the appdata like Andreas Goser suggested and also reinstalled the JRE, as suggested by Jonathan Currie.

What worked for me now, was to open Matlab with the -nojvm option enabled. e.g.

   "...\bin\matlab.exe" -nojvm

After that I could start Matlab normally.

Maybe one start with -nojvm is enough, without the need to remove the appdata or reinstall the JRE. #bestpractices

  1 Comment

Great, thanks, it worked at MATLAB2012a win64 as well.

Answer by Chad Gilbert
on 28 Nov 2012

I've suffered this exact same issue recently. I had to remove my entire "C:\Users\<user>\AppData\Roaming\MathWorks\MATLAB" directory before I was able to re-start MATLAB. This allowed me to boot up MATLAB again, but wreaked havoc on one of my toolboxes.

Has anyone managed to locate more precisely, the configuration issue that these crashes are causing? Have any tips for avoiding similar issues in the future, when using a lot of MEX files?

  1 Comment

Jan Simon
on 4 May 2013

You cannot avoid that a mad MEX function destroyed important information. But a simple backup can decrease the effort required to make the system working again. Therefore I've created a copy of my prefdir folder.

Answer by Jan Simon
on 4 May 2013
Edited by Jan Simon
on 4 May 2013

This is actually a comment to Jonathan Currie's answer, but perhaps it is worth to be written as answer also:

I have created about 200 C-Mex functions in the last 14 years for different Matlab versions also. Therefore I'm familiar with ugly crashes also. While I never had to reinstall Java -and it is not clear to me how a C-function could confuse the JRE at all-, I had corrupted preferences sometimes also. After the first time I've created a backup copy of the prefdir folder, such that I did not need time-consuming uninstall/re-install of Matlab. Deleting the preferences worked for me also.

What could be the reason for a destroyed JRE?

In some cases I had to run restoredefaultpath. This was caused by shadowing built-in functions with a crashing replacement, but this would happen for buggy M-files also.

  1 Comment

I am having a similar problem. MATLAB 2012b will start (at least it appears in the Task Manager as being active) but the GUI never appears. This happened after profiling a CUDA mex file via Nvidia NVVP. There were no crashes during/after profiliong, and I have been using this set of tools for over a year with no problems.

Have tried all the suggestions in this thread, other than re-installation, which I would like to avoid.

Assuming it was the mex which caused the issue, what can be done?

Windows 7 64 bit, MATLAB 2012b, no issues at all until this point.

Answer by Knut
on 7 May 2013

Answer to Michael:

You could also do the following, suggested by Matlab Error-report itself: "...Please check if you have a MATLAB_JAVA environment variable..."

Set the system variable: MATLAB_JAVA = C:\Program Files\Java\jre7 (the current Java7 x64 installation folder)

For us it worked fine!

  1 Comment

I had the same problem and your solution worked for me. However, now I see the system font in bold and hence all fonts in the matlab window are in bold.

Answer by Jan Hermann
on 20 Mar 2015

Had the same problem on OS X with R2014a. In my case, the concerned file was ~/.matlab/R2014a/MATLABDesktop.xml.


Join the 15-year community celebration.

Play games and win prizes!

Learn more
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!