MATLAB Answers

Why do I receive an "undefined function or variable" error when trying to use a built in function of MATLAB or an installed toolbox?

159 views (last 30 days)
When using a built in function of MATLAB I recieve the following error:
??? Undefined function or variable '<function name>'.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 16 Nov 2019
Edited: MathWorks Support Team on 16 Nov 2019
If you are unable to use a built in function from MATLAB or its associated toolboxes, please make sure that the function file is installed.
If you know which toolbox the function belongs to, verify that the toolbox is installed, and that the Release of the toolbox matches the Release of MATLAB, by running this command in your MATLAB command window:
ver
If you do not see the toolbox and you believe that it is installed, try resetting the MATLAB path to the default. MATLAB stores the toolbox information in a cache file. You will need to first update this cache and then reset the path. To do this:
1. Go to the "File" menu to "Preferences"
2. Go to the "General" heading. Click the button "Update Toolbox Path Cache" and press "OK".
3. Go to the "File" menu to "Set Path"
4. Click on "Default", press "OK" to change, then click "Save" and finally "Close".
(If you have added any custom paths to MATLAB, you will need to restore those later)
Run "ver" again to see if the toolbox is installed. If not, you may need to reinstall this toolbox in order to use this function. See the Related Solution: "How do I install additional toolboxes into my existing MATLAB" for more information about installing a toolbox.
Once ver shows your toolbox, run the following command to see if you can find that function:
which -all <function_name>
Replacing <function_name> with the name of the function. You should be presented with the path(s) of the function file. If you get "<function_name> not found", you may need to reinstall that toolbox for the function to be active.
NOTE: If you have multiple instances of that function that are not in the $MATLABROOT\toolbox subfolders (where $MATLABROOT is the installation folder on your machine) you may have a problem running the built in function. See the Related Solution: "Why do I receive an 'undefined function or variable' when using a custom function" for more information.
If you receive the error message "Has no license available" there is a licensing related issue preventing you from using that function. To find the error that is occurring, you can use the following command:
license checkout <toolbox_license_key_name>
Replacing <toolbox_license_key_name> with the proper key name for the toolbox that contains your function. To find the license key name, you will need to look at the INCREMENT lines in your license file. For information on how to find your license file see the related solution: 1-63ZIR6 - "Where are the license files for MATLAB located?"
The license key names of all the toolboxes are located after each INCREMENT tag in the license.dat file. For example:
INCREMENT MATLAB MLM 17 00-jan-0000 0 B454554BADECED4258 \
HOSTID=123456 SN=123456
If your license.dat file has no INCREMENT lines, refer to your license administrator for these INCREMENT lines.
For example, to test the licensing for Symbolic Math Toolbox, you can run this command:
license checkout Symbolic_Toolbox
A correct testing will give the result "ANS=1", otherwise a network license manager error will be presented. You can either troubleshoot the error by looking up the license manager error here:
Or contact the Installation Support Team with the error here:
When contacting support, provide your license number, your MATLAB version, the function you are using, and the network license manager error (if applicable).

More Answers (1)

Ivan Gromyko
Ivan Gromyko on 18 Mar 2017
HELP ME PLEASE!!! I work width Raspberry Pi 3 Model B. I want to use function 'serialdev' in Simulink, but it gives me an error: "Undefined function or variable 'serialdev'". When I work in Mathlab, everything works. As a check, I enter a line: which -all serialdev C:\ProgramData\MATLAB\SupportPackages\R2016b\toolbox\realtime\targets\raspi\raspi.m % raspi method

Sign in to answer this question.

Tags

No tags entered yet.

Products