我有一个代码,可以在3空间中生成两组随机数据,并利用http://cvxr.com/cvx/中的凸优化软件来线性分离数据。我有一个3D图,它显示分隔数据的坐标轴,但我想绘制分离平面。下面列出了轴绘图代码。似乎应该有一种简单的方法来修改它,因为我有平面的法向矢量,但是我在努力进行修改。阅读了https://www.mathworks.com/help/matlab/ref/fimplicit3.html之类的文档并浏览了各种SO线程之后,我只是在寻找可能是最简单的实现。
function drawCoordinateAxes3d(a,b,p1,p2)
an=a/norm(a);
d=b/norm(a);
c=d*an; %point on the line a distance d from the origin
V=null(an'); %to generate a coordinate system, find two vectors orthogonal to an
V=[an V]; %out all three axes in a single matrix
Axis1=[V(:,1),-V(:,1)]; % put two endpoints of axes into Axis1
Axis2=[V(:,2),-V(:,2)];
Axis3=[V(:,3),-V(:,3)];
Axis1=Axis1+[c,c];
Axis2=Axis2+[c,c];
Axis3=Axis3+[c,c];
hold on
axis equal
view(45,45)
plot3(Axis1(1,:),Axis1(2,:),Axis1(3,:),'LineWidth',2);
plot3(Axis2(1,:),Axis2(2,:),Axis2(3,:),'LineWidth',2);
plot3(Axis3(1,:),Axis3(2,:),Axis3(3,:),'LineWidth',2);
% plot all points
for i=1:length(p1)
plot3(p1(1,i),p1(2,i),p1(3,i),'o','MarkerSize',3,'MarkerEdgeColor','k','MarkerFaceColor','g')
hold on
end
for i=1:length(p2)
plot3(p2(1,i),p2(2,i),p2(3,i),'o','MarkerSize',3,'MarkerEdgeColor','k','MarkerFaceColor','r')
hold on
end
grid on
hold off