青年梦想家 发表于 2015-7-28 22:57

【奠基经典】MATLAB实用程序案例之改变坐标轴范围








改变坐标轴范围
实例:


h0=figure('toolbar','none',...
'position',,...
'name','实例44');
h1=axes('parent',h0,...
'position',,...
'visible','on');
e1=uicontrol('parent',h0,...
'style','edit',...
'string',1,...
'position',);
t1=uicontrol('parent',h0,...
'style','text',...
'string','X轴最小值',...
'position',);
e2=uicontrol('parent',h0,...
'style','edit',...
'string',5,...
'position',);
t2=uicontrol('parent',h0,...
'style','text',...
'string','X轴最大值',...
'position',);
e3=uicontrol('parent',h0,...
'style','edit',...
'string',1,...
'position',);
t3=uicontrol('parent',h0,...
'style','text',...
'string','Y轴最小值',...
'position',);
e4=uicontrol('parent',h0,...
'style','edit',...
'string',5,...
'position',);
t4=uicontrol('parent',h0,...
'style','text',...
'string','Y轴最大值',...
'position',);
e5=uicontrol('parent',h0,...
'style','edit',...
'string',20,...
'position',);
t5=uicontrol('parent',h0,...
'style','text',...
'horizontalalignment','left',...
'string','点数',...
'position',);
b1=uicontrol('parent',h0,...
'style','pushbutton',...
'string','绘图',...
'position',,...
'callback',[...
'a=str2num(get(e1,''string''));,',...
'b=str2num(get(e2,''string''));,',...
'c=str2num(get(e3,''string''));,',...
'd=str2num(get(e4,''string''));,',...
'n=str2num(get(e5,''string''));,',...
'xgrid=linspace(-abs(a),abs(a),n);,',...
'ygrid=linspace(-abs(b),abs(b),n);,',...
'=meshgrid(xgrid,ygrid);,',...
'z=c*sqrt(d-y.*y/b/b-x.*x/a/a);,',...
'u=1;,',...
'z1=real(z);,',...
'for k=2:n-1,',...
'for j=2:n-1,',...
'if imag(z(k,j))~=0,',...
'z1(k,j)=0;,',...
'end,',...
'if all(imag(z(,)))~=0,',...
'z1(k,j)=nan;,',...
'end,',...
'end,',...
'end,',...
'surf(x,y,z1),',...
'hold on,',...
'if u==1,',...
'z2=-z1;,',...
'surf(x,y,z2),',...
'axis([-abs(a),abs(a),-abs(b),abs(b),-abs(c),abs(c)]);,',...
'end,',...
'xlabel(''x'');,',...
'ylabel(''y'');,',...
'zlabel(''z'');,',...
'hold off']);
b2=uicontrol('parent',h0,...
'style','pushbutton',...
'string','关闭',...
'position',,...
'callback','close');


关于本帖内容欢迎大家踊跃讨论,与在下交流!

页: [1]
查看完整版本: 【奠基经典】MATLAB实用程序案例之改变坐标轴范围