1. 读取数据的第一种方式
[attrib1,attrib2,attrib3,attrb4,class] = textread('iris.data','%f%f%f%f%s','delimiter',',');
data = [attrib1,attrib2,attrib3,attrb4];
targets = zeros(150,1);
targets(strcmp(class,'Iris-setosa')) = 1;
targets(strcmp(class,'Iris-versicolor')) = 2;
targets(strcmp(class,'Iris-virginica')) = 3;
2. 读取数据的第二种方式
Iris = uiimport('iris.data');
Iris = cellfun(@(x) regexp(x,',','split'), Iris.iris,'UniformOutput',false);
data = cellfun(@(x) x(:,1:4),Iris,'UniformOutput',false);
data = str2double(reshape([data{:}],4,150)');