初次学习matlab设计图形用户界面(GUI)

第一个例子(用matlab实现归一化二阶系统)哈哈。。通过人家代码,了解了不少函数使用方法

%%得到归一化二阶系统的结缘响应曲线坐标图
clf reset%%clf是清除图像窗口中当前图像;reset重置所有对象设置,返回到最初默认状态
H=axes('unit','normalized','position',[0,0,1,1],'visible','off');%%figure左下角坐标为【0 0】,右上角[1 1],坐标不可见
set(gcf,'currentaxes',H);
str='\fontname{隶书}归一化二阶系统的阶跃响应曲线';
text(0.12,0.93,str,'fontsize',13);
h_fig=get(H,'parent');
set(h_fig,'unit','normalized','position',[0.1,0.2,0.7,0.4]);
h_axes=axes('parent',h_fig,'unit','normalized','position',[0.1,0.15,0.55,0.7],...
'xlim',[0 15],'ylim',[0 1.8],'fontsize',8);
%%在坐标右侧生成作解释的“静态文本”和可接受输入的“编辑框”
h_text=uicontrol(h_fig, 'style' , 'text' ,'unit' , 'normalized' , 'position' ,[0.67,0.73,0.25,0.14], ...
'horizontal' , 'left' , 'string' ,{ ' 输入阻尼比系数 ' , 'zeta =' });
h_edit=uicontrol(h_fig, 'style' , 'edit' , 'unit' , 'normalized' , 'position' ,[0.67,0.59,0.25,0.14], ...
'horizontal' , 'left' , 'callback' ,['z=str2num(get(gcbo,''string''));' ,'t=0:0.1:15;' , 'for k=1:length(z);' , ...

需要解释一下:    在edit中输入的是数字,用get得到输入的内容后,再把它转换为数字,然后赋值给z。  

                            gcbo :get current callback object
                            gcf:  get current figure
                            gca: get current axes
                            gcbf: get current callback figure
's2=tf(1,[1 2*z(k) 1]); ' ,'y(:,k)=step(s2,t);' ,'plot(t,y(:,k));' , 'if (length(z)>1) ,hold on,end,' , 'end;' ,'hold off,' ]);

其中tf是传递函数,step:产生阶跃函数
%%生成坐标方格控制按键
h_push1=uicontrol(h_fig, 'style' , 'push' , 'unit' , 'normalized' , 'position' ,[0.67,0.37,0.12,0.15], 'string' , 'grid on' , 'callback' , 'grid on' );
h_push2=uicontrol(h_fig, 'style' , 'push' ,'unit' , 'normalized' , 'position' ,[0.67,0.15,0.12,0.15], 'string' , 'grid off' , 'callback' , 'grid off' );

其中:uicontrol的具体参数定义见http://blog.sina.com.cn/s/blog_6cb6157501015nb4.html

        get与set的具体参数见http://blog.163.com/xiaowshy@126/blog/static/691894272010324111925600/

 

posted @ 2014-05-13 16:53  梦若然  阅读(834)  评论(0编辑  收藏  举报