Why do I receive the error "Undefined function or variable 'usejava'" when trying to start MATLAB 6.x (R12.x)?

21 views (last 30 days)
I receive the following error when I attempt to start MATLAB:
??? Undefined function or variable 'usejava'.
Error in ==> /usr/local/matlabr12/toolbox/local/matlabrc.m
On line 58 ==> if usejava('Desktop')
MATLAB is also not recognizing any basic commands, such as "helpdesk":
helpdesk
The above command results in the following error:
??? Undefined function or variable 'helpdesk'.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This problem usually occurs when your pathdef.m file has become corrupted. The pathdef.m file defines the MATLAB Search Path. If this file has become corrupted, MATLAB will not be able to find any commands to execute.
For information on how to regenerate your pathdef.m file, see the solutions attached at the bottom of this page.
Alternatively, to manually fix the problem, follow these steps:
1. Open the pathdef.m file in any text editor. This file can be found in:
$MATLAB/toolbox/local (where $MATLAB is the root MATLAB directory)
The file will look something like this, depending on which products you have installed and which platform you are on:
function p = pathdef
%PATHDEF Search path defaults.
% PATHDEF returns a string that can be used as input to MATLABPATH
% in order to set the path.
% Copyright 1984-2000 MathWorks, Inc.
% $Revision: 1.4 $ $Date: 2000/06/01 16:19:21 $
% PATH DEFINED HERE -- Don't change this line.
p = [...
matlabroot,'/toolbox/compiler:',...
matlabroot,'/toolbox/images:',...
matlabroot,'/toolbox/local:',...
etc...
2. If you are running under UNIX/Linux, go to the $MATLAB/toolbox directory and obtain a directory listing by typing "ls" at the UNIX prompt. If you are running under Windows, you can just view the contents of this directory with the Windows Explorer.
3. Use the information from Step 2 to correct your pathdef.m file. You should have a listing for each directory within your $MATLAB/toolbox directory. Also, if any of these directories have subdirectories, you will have to add them too. Do not add subdirectories that are titled "private", "ja", or start with a @ symbol. For example, if you have the Control System Toolbox installed, you should have the following listings in your pathdef.m file:
matlabroot,'\toolbox\control\control;',...
matlabroot,'\toolbox\control\ctrlguis;',...
matlabroot,'\toolbox\control\ctrlobsolete;',...
matlabroot,'\toolbox\control\ctrlutil;',...
matlabroot,'\toolbox\control\ctrldemos;',...
This example is from a PC-Windows pathdef.m file. The previous example from Step 1 is from a UNIX/Linux pathdef.m file.
4. When you have added all of the necessary directories to the pathdef.m file, save the file and restart MATLAB. If you are storing files in the $MATLAB/work directory, make sure it is listed in the pathdef.m file as well.

More Answers (1)

Neil Guertin
Neil Guertin on 17 Nov 2017
Instead of rewriting pathdef.m manually, the safest and best way to regenerate it is as follows:
  1. Delete pathdef.m
  2. Recreate pathdef.m as an empty file
  3. Open MATLAB again (You will get some errors)
  4. Run the following commands:
restoredefaultpath
rehash toolboxcache
savepath
This will find all MathWorks toolboxes installed. Any third party toolboxes will have to be added again with "addpath" and "savepath".

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!