MATLAB only supports specific versions of MinGW. R2017b and later supports MinGW 5.3, while R2017a and prior support MinGW 4.9.2. Other versions of MinGW downloaded from third party sources are not qualified to work with MATLAB.
Installation instructions for the release 2017b:
Search for "MATLAB Support for the MinGW-w64 C/C++ Compiler from TDM-GCC" in the MATLAB Add-ons menu.
You can then install the support package from the Add-on explorer.
More information on accessing the Add-ons menu can be found in the following link: