matlab 指定坐标轴范围

[复制链接]
905|0
 楼主| cooldog123pp 发表于 2024-5-25 10:52 | 显示全部楼层 |阅读模式
  1. 指定坐标轴范围

  2. h0=figure('toolbar','none',...
  3.     'position',[198 56 408 468],...
  4.     'name','实例49');
  5. h1=axes('parent',h0,...
  6.     'position',[0.15 0.45 0.7 0.5],...
  7.     'visible','on');
  8. x=0:0.1:2*pi;
  9. y=sin(x);
  10. plot(x,y);
  11. xlabel('X');
  12. ylabel('Y');
  13. title('坐标轴范围的改变');
  14. h=get(gca,'xlim');
  15. k=get(gca,'ylim');
  16. e1=uicontrol('parent',h0,...
  17.     'style','edit',...
  18.     'string',eval(num2str(h(1))),...
  19.     'horizontalalignment','right',...
  20.     'position',[80 120 100 20]);
  21. t1=uicontrol('parent',h0,...
  22.     'style','text',...
  23.     'string','X轴最小值',...
  24.     'position',[100 145 80 20]);
  25. e2=uicontrol('parent',h0,...
  26.     'style','edit',...
  27.     'string',eval(num2str(h(2))),...
  28.     'horizontalalignment','right',...
  29.     'position',[80 60 100 20]);
  30. t2=uicontrol('parent',h0,...
  31.     'style','text',...
  32.     'string','X轴最大值',...
  33.     'position',[100 85 80 20]);
  34. e3=uicontrol('parent',h0,...
  35.     'style','edit',...
  36.     'string',eval(num2str(k(1))),...
  37.     'horizontalalignment','right',...
  38.     'position',[250 120 100 20]);
  39. t3=uicontrol('parent',h0,...
  40.     'style','text',...
  41.     'string','Y轴最小值',...
  42.     'position',[270 145 80 20]);
  43. e4=uicontrol('parent',h0,...
  44.     'style','edit',...
  45.     'string',eval(num2str(k(2))),...
  46.     'horizontalalignment','right',...
  47.     'position',[250 60 100 20]);
  48. t4=uicontrol('parent',h0,...
  49.     'style','text',...
  50.     'string','X轴最小值',...
  51.     'position',[270 85 80 20]);
  52. p1=uicontrol('parent',h0,...
  53.     'style','pushbutton',...
  54.     'string','设置',...
  55.     'position',[105 10 50 30],...
  56.     'callback',[...
  57.         'a=str2num(get(e1,''string''));,',...
  58.         'b=str2num(get(e2,''string''));,',...
  59.         'c=str2num(get(e3,''string''));,',...
  60.         'd=str2num(get(e4,''string''));,',...
  61.         'axis([a b c d]),',...
  62.         'drawnow']);
  63. p2=uicontrol('parent',h0,...
  64.     'style','pushbutton',...
  65.     'string','关闭',...
  66.     'position',[275 10 50 30],...
  67.     'callback','close');


您需要登录后才可以回帖 登录 | 注册

本版积分规则

2304

主题

7629

帖子

31

粉丝
快速回复 在线客服 返回列表 返回顶部