一.下载libsvm
http://www.csie.ntu.edu.tw/~cjlin/libsvm/
在libsvm的网站上下载 libsvm-3.12.zip文件,解压后放在任意目录下,最好放在MATLAB工具箱中,比如 C:\Program Files\MATLAB\R2011a\toolbox\libsvm-3.12下。
二。具体说说如何选择编译器。
- 首先在MATLAB命令窗【Commond Window】中输入:mex -setup
- 会出现类似如下内容:
Would you like mex to locate installed compilers [y]/n?
- 这里问你是否locate本机安装的编译器,正规的选择y然后指定编译器即可,我们先来看一下选择y(选择n在后面说),好下面我们选择y。
- 根据你本机安装的编译器,会出现类似如下内容:
Would you like mex to locate installed compilers [y]/n? y
Select a compiler:
[1] Lcc-win32 C 2.4.1 in D:\MATLAB~1\sys\lcc
[2] Microsoft Visual C++ 6.0 in D:\Microsoft Visual Studio
[0] None
Compiler:
- 然后你选择相应的编译器并确认即可:
Please verify your choices:
Compiler: Microsoft Visual C++ 6.0
Location: D:\Microsoft Visual Studio
Are these correct [y]/n? y
Trying to update options file: C:\Users\faruto\AppData\Roaming\MathWorks\MATLAB\R2009b\mexopts.bat
From template: D:\MATLAB~1\bin\win32\mexopts\msvc60opts.bat
Done . . .
PS:matlab支持的编译器列表在这里查看:
http://www.mathworks.com/support/compilers/current_release/
这样就表示编译器选择成功了(此步骤中可能会出现warning警告是正常现象,不用管的说~)。
- 如果你输入 mex –setup后在
Would you like mex to locate installed compilers [y]/n?
- 这一步选择y后,可选择的编译器里面有没你已经安装的编译器,表示MATLAB可能没有识别记录你安装的编译器的名字和目录(有时候会发生这种情况),此时你应该重新输入 mex –setup后选择n手动进行编译器的设置:
Please choose your compiler for building external interface (MEX) files:
Would you like mex to locate installed compilers [y]/n? n
Select a compiler:
[1] Intel C++ 9.1 (with Microsoft Visual C++ 2005 SP1 linker)
[2] Intel Visual Fortran 10.1 (with Microsoft Visual C++ 2005 SP1 linker)
[3] Lcc-win32 C 2.4.1
[4] Microsoft Visual C++ 6.0
[5] Microsoft Visual C++ .NET 2003
[6] Microsoft Visual C++ 2005 SP1
[7] Microsoft Visual C++ 2008 Express
[8] Microsoft Visual C++ 2008 SP1
[9] Open WATCOM C++
[0] None
- Compiler: 4 %选择的这个编译器一定是你本机安装了的,否则选择了也没有用
D:\Microsoft Visual Studio. Do you want to use this compiler [y]/n?
- 这样的话就可以手动选择你想要的编译器了,在
D:\Microsoft Visual Studio. Do you want to use this compiler [y]/n?
- 这个确认步骤,如果你的编译器的确是安装在MATLAB给出的这个目录(我这里是D:\Microsoft Visual Studio)那么选择y确认即可,如果不是说明MATLAB没有识别出安装的地方,选择n手动指定目录即可,比如选择n后的结果如下:
Your machine has a Microsoft Visual C++ compiler located at
D:\Microsoft Visual Studio. Do you want to use this compiler [y]/n? n
Please enter the location of your compiler: [C:\Program Files\Microsoft Visual Studio]
- 此时输入你安装的编译器的完整目录即可比如:D:\Microsoft Visual Studio
3. 编译文件(make)
这一步说白了就是运行一下 libsvm-mat工具箱中的make.m文件。
- 首先需要把MATLAB的当前目录[Current Folder]调整到libsvm-mat所在的文件夹
- 然后在MATLAB命令窗【Commond Window】输入make
load heart_scale;
model = svmtrain(heart_scale_label,heart_scale_inst);
[predict_label,accuracy] = svmpredict(heart_scale_label,heart_scale_inst,model);
如果出现下面这个结果,则说明肯定安装成功了:
Accuracy = 86.6667% (234/270) (classification)