The solution is to have an administrator set the environment variable on your system. Your local IT administrator should be able to help with this. On Windows 10, you can find this panel by entering "Edit the system environment variables" in the Windows search:
The environment variable should have the following name and value:
- Variable Name: MW_MINGW64_LOC
- Variable Value: <SupportPackageRoot>\3P.instrset\mingw_w64.instrset or <SupportPackageRoot>\MW_MinGW_x_x for older versions of MATLAB
where <SupportPackage Root> is the output received for the command:
>> matlabshared.supportpkg.getSupportPackageRoot
Now, running the 'getenv' command in MATLAB should return the desired value, and you should be able to select MinGW64 compiler using 'mex -setup':
>> getenv('MW_MINGW64_LOC')
ans =
'C:\ProgramData\MATLAB\SupportPackages\R2021a\3P.instrset\mingw_w64.instrset'
>> mex -setup
MEX configured to use 'MinGW64 Compiler (C)' for C language compilation.
Note that the release number shown above may differ if you're not using R2021a.