Matlab生成二类线性可分数据

%% 生成二类线性可分数据
function [feature, category]=generate_sample(step,error)
aa=3; %斜率
bb=3; %截距
b1=1;   
rr =error;
s=step;

x1(:,1) = -1:s:1;
n = length(x1(:,1));
x1(:,2) = aa.*x1(:,1) + bb + b1 + rr*abs(randn(n,1));
y1 = -ones(n,1);
x2(:,1) =  -1:s:1;
x2(:,2) = aa.*x2(:,1) + bb - b1 - rr*abs(randn(n,1));
y2 = ones(n,1);
%figure;
%plot(x1(:,1),x1(:,2),'bx',x2(:,1),x2(:,2),'k.');
feature=[x1;x2];
category=[y1;y2];

去吧,去吧,到彼岸去吧,彼岸是光明的世界!
原文地址:https://www.cnblogs.com/lengyue365/p/5043863.html