用鼠标左键绘制折线,同时在鼠标左键点中的位置输出一个含有该位置信息的字符串,利用鼠标中键或右键终止绘制。

解:建立一个Untitled.m文件

MATLAB指令:

clf;axis([0,10,0,5]);hold on

x=[];y=[];

for i=1:100

   [x1,y1,button]=ginput(1);

   chstr=['(',num2str(x1),',',num2str(y1),')'];text(x1,y1,chstr);

   x=[x,x1];y=[y,y1];line(x,y);

   pause(1);

   if(button~=1);break;end

end

   hold off

结果:

用鼠标左键绘制折线,利用鼠标中键或右键终止绘制

转载于:https://blog.51cto.com/yaoyaolx/1754465

相关文章:

  • 2021-11-24
  • 2022-12-23
  • 2021-11-02
  • 2022-12-23
  • 2021-12-12
  • 2021-10-22
  • 2021-11-23
  • 2022-02-08
猜你喜欢
  • 2022-12-23
  • 2021-06-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
相关资源
相似解决方案