Since I am unaware of the MATLAB release at your end, following are a few workarounds which have worked in different scenarios:
- Protecting a model might generate an error "Undefined function or variable 'templateMakefile'". This is a known issue in MATLAB R2013a and a detailed workaround has been provided in the following External Bug Report: https://www.mathworks.com/support/bugreports/911899?s_tid=srchtitle
- It is possible that specification of template makefile for generation of the makefile is missing altogether in the model configuration. Refer to the following documentation link for information on how to specify template makefile from which to generate the makefile: https://www.mathworks.com/help/rtw/ref/template-makefile.html?searchHighlight=templateMakefile&s_tid=srchtitle.
This error can also occur when MATLAB does not recognize the specified string as the name of a function on the MATLAB path or as a variable. "Undefined function or variable" can be caused by:
- A typographical error when typing a function or variable name (such as typing a 1 [one] when you intended to type an l [low-case L]). However, later versions of MATLAB try to resolve these typos with “Did you mean” suggestions.
- The wrong case for a function or variable name. Later versions of MATLAB try to resolve these typos with “Did you mean” suggestions.
- Changing directories so that a function you used is no longer on the MATLAB path.
- Trying to use a function for which you are not licensed or that belongs to a toolbox that isn’t installed. In later versions of MATLAB, this is not an “Undefined function or variable” error, and MATLAB lets you know that you are either not licensed to use the function or the appropriate toolbox is not installed.
- Calling an object method without an object as the first input.
- Using a MEX function that is compiled on a platform different from the one in use.
Verify that the undefined function or variable is visible (it is on the path or in the current workspace) and that it has been defined before this line of code executes.
If you are certain the variable or function exists, verify the case of the function or variable name. If the undefined identifier is a function, the 'which' function can help you verify that it is visible to the function where the error occurs.
If you are having problems with your MATLAB search path, run the following MATLAB commands and then restart MATLAB.
Hope this helps!
DISCLAIMER: These are my own views and in no way depict those of MathWorks.