matlab 呼叫mex -setup問題

裝了visual studio 2015,可是在matlab中呼叫失敗了。

>> mex -setup
Error using mex
No supported compiler or SDK was found. For options, visit 
http://www.mathworks.com/support/compilers/R2015a/win64.html.

嘗試去裝SDK,還是不行。下面介紹一個可行的方法,也許對你有用。

下載gnumex,地址:https://sourceforge.net/projects/gnumex/?source=typ_redirect
下載Rtools,一個開發R語言的工具,地址:https://cran.r-project.org/bin/windows/Rtools/,下載好後安裝。
下載Cygwin,地址:https://www.cygwin.com/,下載好後安裝。
將gnumex解壓到matlab目錄下,並將matlab的目錄切換到該檔案的主目錄下。在matlab的命令列中輸入:

>> gnumex

會彈出一個GUI 框:
這裡寫圖片描述

安裝圖中的選擇好目錄,最後點選Make options file,稍作等待幾分鐘,就OK了。

看結果:

>> mex -setup
Warning: Legacy MEX infrastructure is provided for compatibility; it will be removed in a future
version of MATLAB. For more information, consult the MEX release notes
http://www.mathworks.com/help/matlab/release-notes.html. 
Welcome to mex -setup.  This utility will help you set up  
a default compiler.  For a list of supported compilers, see  
http://www.mathworks.com/support/compilers/R2015a/win64.html 
Please choose your compiler for building MEX-files: 
Would you like mex to locate installed compilers [y]/n? y
Select a compiler: 
[1] gcc in D:\Rtools\GCC-46~1.3\bin 
[0] None 
Compiler: 1
Please verify your choices: 
Compiler: gcc  
Location: D:\Rtools\GCC-46~1.3\bin 
Are these correct [y]/n? y
Trying to update options file: C:\Users\mingzi\AppData\Roaming\MathWorks\MATLAB\R2015a\mexopts.bat 
From template:              F:\matlab\bin\win64\mexopts\GNUMEXOPTS.bat 
Done . . . 
************************************************************************** 
Warning: The MATLAB C and Fortran API has changed to support MATLAB 
variables with more than 2^32-1 elements.  In the near future 
you will be required to update your code to utilize the new 
API. You can find more information about this at: 
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html  
Building with the -largeArrayDims option enables the new API. 
************************************************************************** 

上面有些地方需要做出選擇,根據情況來選擇即可。