What is wrong with my code.I want to connect stars(*)by straight line,but it's printing only points,not line!

1 回表示 (過去 30 日間)
function draw_constellations
set(gcf,'color','m');
set(gca,'color','m');
axis([0 100 0 100])
hold on;
while 1
[x,y,button]=ginput(1);
switch button
case 1
plot(x,y,'w*-');
case{'q','Q'}
break;
end
end
end

回答 (1 件)

Steven Lord
Steven Lord 2020 年 5 月 29 日
You're creating one line per ginput call, plotting one point per line. They're not all the same line object so they're not connected. I would create an animatedline object before entering the while loop and addpoints to it inside.
h = animatedline('Marker', '*', 'LineStyle', '-');
while 1
[x,y,button]=ginput(1);
switch button
case 1
addpoints(h, x, y);
case{'q','Q'}
break;
end
end
  2 件のコメント
vidushi Chaudhary
vidushi Chaudhary 2020 年 5 月 29 日
How to white color to the points & line?
Steven Lord
Steven Lord 2020 年 5 月 29 日
Specify additional properties of the animatedline when you construct it, like I did with the Marker and LineStyle properties. The properties you can change are listed on this documentation page.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by