01--范围限制

当某输入工况落在两个边界值之间,则输出置1,且该两个边界可选。

比如,燃电电堆可以设定一个最佳工作温度,当工作的温度在最佳工作温度范围内时,输出1

伪代码:

输入温度为x,输出标志位为y,温度范围边界为a和b

那么有:

a<=x<=b,y=1,

若边界可选则分为如下情况

a<=x<=b,a<x<=b,a<=x<b,a<=x<=b,

建模:

stateflow

将该状态机进行封装子系统,

封装选项卡按如下设置:

Icon & Ports:

Icon drawing commands 中m脚本:

 
if   strcmp(get_param(gcbh, 'ShowOutp1'), 'on')
     text(0.5,0.78,['\fontsize{10}\color{green}a \color{orange}≤ \color{green}x \color{orange}≤\color{green} b'],'verticalAlignment','Bottom','horizontalAlignment','Center','texmode','on');
 end
 if  strcmp(get_param(gcbh, 'ShowOutp2'), 'on')
     text(0.5,0.53,['\fontsize{10}\color{green}a \color{orange}< \color{green}x \color{orange}≤ \color{green}b'],'verticalAlignment','Bottom','horizontalAlignment','Center','texmode','on');
 end
 if  strcmp(get_param(gcbh, 'ShowOutp3'), 'on')
     text(0.5,0.28,['\fontsize{10}\color{green}a \color{orange}≤ \color{green}x \color{orange}< \color{green}b'],'verticalAlignment','Bottom','horizontalAlignment','Center','texmode','on');
 end
  if  strcmp(get_param(gcbh, 'ShowOutp4'), 'on')
     text(0.5,0.05,['\fontsize{10}\color{green}a \color{orange}< \color{green}x \color{orange}< \color{green}b'],'verticalAlignment','Bottom','horizontalAlignment','Center','texmode','on');
 end

Parameter & Dialog:

Initialization:

set_param(gcb, 'MaskSelfModifiable', 'on');
prtnum = 0;
if   strcmp(get_param(gcbh, 'ShowOutp1'), 'on')
	 replace_block([gcb '/flg1'],'Terminator','Outport','noprompt');
     prtnum = prtnum +1;
     set_param([gcb '/flg1'],'Port',num2str(prtnum));
 else
	 replace_block([gcb '/flg1'],'Outport','Terminator','noprompt');
 end
 if  strcmp(get_param(gcbh, 'ShowOutp2'), 'on')
	 replace_block([gcb '/flg2'],'Terminator','Outport','noprompt');
     prtnum = prtnum +1;
     set_param([gcb '/flg2'],'Port',num2str(prtnum));
 else
	 replace_block([gcb '/flg2'],'Outport','Terminator','noprompt');
 end
 if  strcmp(get_param(gcbh, 'ShowOutp3'), 'on')
	 replace_block([gcb '/flg3'],'Terminator','Outport','noprompt');
     prtnum = prtnum +1;
     set_param([gcb '/flg3'],'Port',num2str(prtnum));     
 else
	 replace_block([gcb '/flg3'],'Outport','Terminator','noprompt');
 end
  if  strcmp(get_param(gcbh, 'ShowOutp4'), 'on')
	 replace_block([gcb '/flg4'],'Terminator','Outport','noprompt');
     prtnum = prtnum +1;
     set_param([gcb '/flg4'],'Port',num2str(prtnum));      
 else
	 replace_block([gcb '/flg4'],'Outport','Terminator','noprompt');
 end

Documentation:

最终效果:

 输出可以针对边界进行选择。

Logo

欢迎加入 MCP 技术社区!与志同道合者携手前行,一同解锁 MCP 技术的无限可能!

更多推荐