改变坐标轴范围

[复制链接]
782|0
 楼主| cooldog123pp 发表于 2024-2-24 21:08 | 显示全部楼层 |阅读模式
  1. h0=figure('toolbar','none',...
  2.     'position',[198 56 408 468],...
  3.     'name','实例44');
  4. h1=axes('parent',h0,...
  5.     'position',[0.15 0.45 0.7 0.5],...
  6.     'visible','on');
  7. e1=uicontrol('parent',h0,...
  8.     'style','edit',...
  9.     'string',1,...
  10.     'position',[50 120 50 20]);
  11. t1=uicontrol('parent',h0,...
  12.     'style','text',...
  13.     'string','X轴最小值',...
  14.     'position',[35 150 80 20]);
  15. e2=uicontrol('parent',h0,...
  16.     'style','edit',...
  17.     'string',5,...
  18.     'position',[50 60 50 20]);
  19. t2=uicontrol('parent',h0,...
  20.     'style','text',...
  21.     'string','X轴最大值',...
  22.     'position',[35 90 80 20]);
  23. e3=uicontrol('parent',h0,...
  24.     'style','edit',...
  25.     'string',1,...
  26.     'position',[150 120 50 20]);
  27. t3=uicontrol('parent',h0,...
  28.     'style','text',...
  29.     'string','Y轴最小值',...
  30.     'position',[135 150 80 20]);
  31. e4=uicontrol('parent',h0,...
  32.     'style','edit',...
  33.     'string',5,...
  34.     'position',[150 60 50 20]);
  35. t4=uicontrol('parent',h0,...
  36.     'style','text',...
  37.     'string','Y轴最大值',...
  38.     'position',[135 90 80 20]);
  39. e5=uicontrol('parent',h0,...
  40.     'style','edit',...
  41.     'string',20,...
  42.     'position',[250 120 50 20]);
  43. t5=uicontrol('parent',h0,...
  44.     'style','text',...
  45.     'horizontalalignment','left',...
  46.     'string','点数',...
  47.     'position',[250 150 30 20]);
  48. b1=uicontrol('parent',h0,...
  49.     'style','pushbutton',...
  50.     'string','绘图',...
  51.     'position',[250 60 60 40],...
  52.     'callback',[...
  53.         'a=str2num(get(e1,''string''));,',...
  54.         'b=str2num(get(e2,''string''));,',...
  55.         'c=str2num(get(e3,''string''));,',...
  56.         'd=str2num(get(e4,''string''));,',...
  57.         'n=str2num(get(e5,''string''));,',...
  58.         'xgrid=linspace(-abs(a),abs(a),n);,',...
  59.         'ygrid=linspace(-abs(b),abs(b),n);,',...
  60.         '[x,y]=meshgrid(xgrid,ygrid);,',...
  61.         'z=c*sqrt(d-y.*y/b/b-x.*x/a/a);,',...
  62.         'u=1;,',...
  63.         'z1=real(z);,',...
  64.         'for k=2:n-1,',...
  65.         'for j=2:n-1,',...
  66.         'if imag(z(k,j))~=0,',...
  67.         'z1(k,j)=0;,',...
  68.         'end,',...
  69.         'if all(imag(z([k-1:k+1],[j-1:j+1])))~=0,',...
  70.         'z1(k,j)=nan;,',...
  71.         'end,',...
  72.         'end,',...
  73.         'end,',...
  74.         'surf(x,y,z1),',...
  75.         'hold on,',...
  76.         'if u==1,',...
  77.         'z2=-z1;,',...
  78.         'surf(x,y,z2),',...
  79.         'axis([-abs(a),abs(a),-abs(b),abs(b),-abs(c),abs(c)]);,',...
  80.         'end,',...
  81.         'xlabel(''x'');,',...
  82.         'ylabel(''y'');,',...
  83.         'zlabel(''z'');,',...
  84.         'hold off']);
  85. b2=uicontrol('parent',h0,...
  86.     'style','pushbutton',...
  87.     'string','关闭',...
  88.     'position',[150 10 60 20],...
  89.     'callback','close');


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

本版积分规则

2304

主题

7627

帖子

31

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