0
下面是我的matlab代碼,它圍繞原點旋轉時繪製黑線。在大多數情況下,代碼的作品,但因爲我使用'堅持',一旦我畫了一條線,它就停留在整個程序。設置爲一個圖的某些部分,而不是其他人
我想要的是更像鐘錶上的秒針(只逆時針方向移動)。對於i的特定值,黑線會打印出來,並且在我增量後,前一行消失。但是,我希望紅線和藍線以及繪製的文本從迭代到迭代都保持在圖上。我嘗試使用set()命令,無法讓它工作,有什麼想法?
scalar = 3;
a = [3/scalar 2/scalar];
b = [-4/scalar .5/scalar];
starts = zeros(2,2);
ends = [a;b];
hold on
quiver(0,0,a(1),a(2),'color',[0 0 1],'linewidth',3);
quiver(0,0,b(1),b(2),'color',[1 0 0],'linewidth',3);
axisSize = 15/scalar;
axis([-axisSize axisSize -axisSize axisSize])
mintheta = [500, 500];
%waitforbuttonpress
for i=1:360
theta = [cos(2*pi()*i/360) sin(2*pi()*i/360)];
minDot = min(a*theta',-1*(b*theta'));
theta = theta/minDot;
hold on
if (minDot > 0)
if (norm(theta) < norm(mintheta))
mintheta = theta;
end
text(-4.5, 4, 'Drawing all Theta vectors,');
text(-4.5, 3.7, 'according to constraint that');
text(-4.5, 3.4, 'all dotProducts >= 1');
text(-4.5, 2.5, 'Yellow indicates a non-separating plane,');
text(-4.5, 2.2, 'SVM looks for shortest possible');
text(-4.5, 1.9, 'Theta (will be shown in green).');
quiver(0,0,theta(1),theta(2),'color',[0 0 0],'linewidth',5);
quiver(0,0,3/scalar,2/scalar,'color',[0 0 1],'linewidth',3);
quiver(0,0,-4/scalar,.5/scalar,'color',[1 0 0],'linewidth',3);
axis([-axisSize axisSize -axisSize axisSize])
else
quiver(0,0,cos(2*pi()*i/360),sin(2*pi()*i/360),'color',[1 1 0],'linewidth',5);
end
pause(.05);
end
quiver(0,0,mintheta(1),mintheta(2),'color',[0 1 0],'linewidth',3);
我很感激幫助。非常感謝。 – user1956609