I encountered the same problem (one difference: Matlab veriosn 2020a) as Akhila running initCobraToolbox and also running other code which calls changeCobraSolver.m. I noticed the following when trying to find the cause:
when reaching
changeCobraSolver.m line 445 and following :
case {'ibm_cplex','cplexlp'}
try
ILOGcplex = Cplex('fba'); % Initialize the CPLEX object
solverOK = true;
catch ME
solverOK = false;
end
matver=split(version,'.');
matver=str2double(strcat(char(matver(1)),'.',char(matver(2))));
if matver < 8.6
warning('off', 'MATLAB:lang:badlyScopedReturnValue'); % take out warning message
end
this generates an exception, which is not reported, but the exception is caught and solverOK is set to 'false'. If the call to Cplex is commented out at first glance the installation seems to be OK, but problems arise on further calls to Cplex().
The exception is something like:
K>> ILOGcplex = Cplex('fba')
Error using Cplex
Error:File: Cplex.p Line: 942 Column: 0
Identifier 'changedParam' is not a function or a shared variable. To
share 'changedParam' with nested function, initialize it in the current
scope. For more information, see Sharing Variables Between Parent and
Nested Functions.
at another occasion:
ME =
MException with properties:
identifier: 'MATLAB:lang:IdentifierNotSharedVariableWithNestedScope'
message: 'Error:File: Cplex.p Line: 942 Column: 0↵Identifier 'changedParam' is not a function or a shared variable. To share 'changedParam' with nested function, initialize it in the current scope. For more information, see Sharing Variables Between Parent and Nested Functions.'
cause: {}
stack: [4×1 struct]
Correction: []
Cplex.p is a content-obscured, executable file and I do not know how to search further.
The problem arises each time Cplex() is called via initCobraToolbox or during other calls to changeCobraSolver.
At one occasion there was also mention of Cplex not being installed or the IBM license server not being reached.
However, other calls of Cplex functions in matlab code which does not use the cobratoolbox still work well.
Kind Regards,
Hans van Beek