错误使用 svmtrain svmtrain has been removed. Use fitcsvm instead.Y must be a vector or a character array

错误1

错误使用 svmtrain (line 230)
svmtrain has been removed. Use fitcsvm instead.

错误2

错误使用 svmtrain (line 233)
Y must be a vector or a character array.

相信看到这片文章的同学不是遇到了错误1就是遇到了错误2

而这俩错误的原因都是一个就是,你的MATLAB不支持这个svmtrain函数

错误1是由于你的MATLAB版本有点高,比如2018b会遇到这个问题,在新版本中svmtrain函数已经被淘汰了

错误2是由于你的MATLAB版本有点低,比如2014b会遇到这个问题,在老版本中svmtrain函数和你想象的有点不同

解决方法

首先要先下载libsvm工具,下载地址,直接进去下载。免费的哦~
错误使用 svmtrain svmtrain has been removed. Use fitcsvm instead.Y must be a vector or a character array
傻瓜教程,然后解压
错误使用 svmtrain svmtrain has been removed. Use fitcsvm instead.Y must be a vector or a character array
将上述文件夹放到MATLAB安装路径下:
C:\Program Files\MATLAB\R2018b\toolbox
这个是我的安装路径(默认装在了C盘),将libsvm-3.24文件夹放到toolbox文件夹里面。
错误使用 svmtrain svmtrain has been removed. Use fitcsvm instead.Y must be a vector or a character array
然后转到MATLAB里面操作

将刚才libsvm-3.24文件夹的路径导入到MATLAB里,
下面这个动图应该展示的很清楚了
错误使用 svmtrain svmtrain has been removed. Use fitcsvm instead.Y must be a vector or a character array
这时,再次运行程序,你会奇迹般地发现成功了~