It is probably because the environment variable MW_MINGW64_LOC is not set correctly during installation. Usually this variable should be set with the path of the MinGW installation folder. However, on some systems where users have limited privileges, there may policies in place preventing environment variables from being set.
In order to see whether the MW_MINGW64_LOC environment variable is set, run the "mex" command in verbose mode:
The solution is to have an administrator set the variable.
Please refer to the following MATLAB Answers post for more information: