这是画一个开口水箱,显示水位变化的动态图像。麻烦大神能一步步详细解释下case2这部分代码。谢谢!function [sys,x0]=animtank(t,x,u,flag,ts) global tankdemoif flag==2,if any(get(0,'Children')==tankdemo),if strcmp(get(tankdemo,'Name'),'Tank Demo'),% Update tank one leveltankHndlList=get(tankdemo,'UserData');yData=get(tankHndlList(1),'YData');yOffset=yData(1);yData(3:4)=[1 1]*u(2)+yOffset;set(tankHndlList(1),'YData',yData);yData=get(tankHndlList(2),'YData');yData([3 4])=[1 1]*u(2)+yOffset;set(tankHndlList(2),'YData',yData);yData=[1 1]*u(1)+1;set(tankHndlList(3),'YData',yData);drawnow;endendsys=[];x0=[];elseif flag==0;% Initialize the figure for use with this simulationfuzzy_animinit('Tank Demo');tankdemo=findobj(0,'Name','Tank Demo');tank1Wid=1;tank1Ht=2;tank1Init=0;setPt=0.5;tankX=[0 0 1 1]-0.5;tankY=[1 0 0 1];% Draw the tankline(1.1*tankX*tank1Wid+1,tankY*tank1Ht+0.95,'LineWidth',2,'Color','black');tankX=[0 1 1 0 0]-0.5;tankY=[0 0 1 1 0];% Draw the waterwaterX=tankX*tank1Wid+1;waterY=tankY*tank1Init+1;tank1Hndl=patch(waterX,waterY,'blue','EdgeColor','none');% Draw the gray wallwaterY([1 2 5])=tank1Ht*[1 1 1]+1;waterY([3 4])=tank1Init*[1 1]+1;tank2Hndl=patch(waterX,waterY,[.9 .9 .9],'EdgeColor','none');% Draw the set pointlineHndl=line([0 0.4],setPt*[1 1]+1,'Color','red','LineWidth',4);set(gcf, ...'Color',[.9 .9 .9], ...'UserData',[tank1Hndl tank2Hndl lineHndl]);set(gca, ...'XLim',[0 2],'YLim',[0 3.5], ...'XColor','black','YColor','black', ...'Box','on');axis equalxlabel('Water Level Control','Color','black','FontSize',10);set(get(gca,'XLabel'),'Visible','on')sys=[0 0 0 2 0 0];x0=[];end;
1 回答
红糖糍粑
TA贡献1815条经验 获得超6个赞
tankdemo是画出来的那个figure对象
figure对象有着很复杂的结构
set是设置对象属性值的函数
get是获取对象属性值的函数
就是更新'UserData'数据 比如这段代码: tankHndlList=get(tankdemo,'UserData'); 读原来的'UserData'数据 yData=get(tankHndlList(1),'YData'); 读'UserData'中的第一个对象的'YData'属性值 yOffset=yData(1); 其中第一个当作偏置量 yData(3:4)=[1 1]*u(2)+yOffset; 更新计算yData set(tankHndlList(1),'YData',yData); 更新tankHndlList(1) 其他的代码也是这个目的
- 1 回答
- 0 关注
- 104 浏览
添加回答
举报
0/150
提交
取消