我正在尝试运行以下功能,以便可以绘制由一条线连接的一些点,但是这些线未以我想要的颜色(白色)显示。我也尝试了其他颜色,但线条仍然无法显示。我不明白为什么。有人可以帮忙吗?
function draw_constellations
figure
hold on
axis([0,100,0,100])
grid off
set(gcf,'color','k')
set(gca,'color','k')
axis square
while 1
[x,y,button] = ginput(1);
switch button
case 1 % left mouse
p = plot(x,y,'w-*');
case {'q','Q'} % on keyboard
break;
end
end
这是因为x
和y
您以前绘制的是缩放器。为了情节线索,您将需要存储所有x
和y
你得到ginput
的载体和绘制矢量:
[x,y,button] = ginput(1);
switch button
case 1 % left mouse
xs = [xs x];
ys = [ys y];
p = plot(xs,ys,'w-*');
% more code to go
end
但是,如果在每次输入新点时都绘制xs
和,则ys
线会重叠。为避免这种情况,我们只绘制第一个点并更新p.XData
和p.YData
为新点:
if isempty(p)
p = plot(x,y,'w-*');
else
p.XData = xs;
p.YData = ys;
完整代码:
figure
hold on
axis([0,100,0,100])
grid off
set(gcf,'color','k')
set(gca,'color','k')
axis square
xs = [];
ys = [];
p = [];
while 1
[x,y,button] = ginput(1);
switch button
case 1 % left mouse
xs = [xs x];
ys = [ys y];
if isempty(p)
p = plot(x,y,'w-*');
else
p.XData = xs;
p.YData = ys;
end
case {'q','Q'} % on keyboard
break;
end
end
结果:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句