📄 sb2slswt.m
字号:
function sb2slswt(blkname,in,fl,cod,timer)
%SB2SLSWT converts switch blocks to SIMULINK.
% SB2SLSWT(BLKNAME,IN,FL,COD,TIMER) converts a SystemBuild block
% to a SIMULINK block. BLKNAME is a string containing the name of
% the block. The parameters are set up for this block based on the
% SystemBuild file coding integer IN and real number FL.
%
% COD is a three dimensional vector. The first element indicates
% whether it is a continuous (0) or discrete (1) time system.
% The second element indicates whether it does not need (0) or
% does need (1) a mask. The third element indicates the
% orientation of the block.
%
% TIMER is designed for discrete time only. The first element of
% TIMER is the sampling time. The second element is the initial time.
% Wes Wang 11/12/92
% Copyright (c) 1990-93 by The MathWorks, Inc.
% $Revision: 1.11 $ $Date: 1993/06/09 22:09:40 $
% in = [8, code1 code2, input, output, state,....
% state / output --> order of integer for each one
% if input > output --> resettable
% (input - 1)/output - 1 = highest order resettable
% this one works the same for continuous or discrete time systems
%
% swt works for 11:5
set_param(blkname,'Location',[403,158,1051,158+120*3])
set_param([blkname '/input1'],'position',[35,50,55,70]);
for i=1:in(5)
x = 52 + (i-1)*100;
set_param([blkname '/input' num2str(i+1)],...
'Port',num2str(i+1),...
'position',[115,x+18,135,x+38]);
set_param([blkname '/input' num2str(i+in(5)+1)],...
'Port', num2str(i+in(5)+1),...
'position',[155,x+38,175,x+58]);
add_block('built-in/Mux',[blkname '/Mux' num2str(i)])
set_param([blkname '/Mux' num2str(i)],...
'inputs','3',...
'position',[205,x,235,x+56]);
autoline(blkname,'input1/1',['Mux' num2str(i) '/1']);
autoline(blkname,['input' num2str(i+1) '/1'],['Mux' num2str(i) '/2']);
autoline(blkname,['input' num2str(i+in(5)+1) '/1'],['Mux' num2str(i) '/3']);
add_block('built-in/Fcn',[blkname '/Fcn' num2str(i)])
% temp = '(u[1]==0)*u[2] + (u[1]>=Tol || u[1]<0)*u[3] + (u[1]>0 &&';
% temp = [temp ' u[1]<Tol)*(u[1]/Tol*u[3] + (Tol - u[1])/Tol*u[2])'];
temp = '(u[1]==0)*u[3] + ((u[1]>=Tol) || (u[1]<0))*u[2] + ((u[1]>0) &&';
temp = [temp ' (u[1]<Tol))*(u[1]/Tol*u[3] + (Tol - u[1])/Tol*u[2])'];
set_param([blkname '/Fcn' num2str(i)],'Expr',temp,...
'position',[295,x,435,x+56])
autoline(blkname,['Mux' num2str(i) '/1'], ['Fcn' num2str(i) '/1']);
set_param([blkname '/output' num2str(i)],'Port',num2str(i),...
'position',[465,x+18,485,x+38]);
autoline(blkname,['Fcn' num2str(i) '/1'],['output' num2str(i) '/1']);
end;
set_param(blkname,'Mask Display',...
'plot(0,1.2,10,10.5,[0 5 5 4.5 5.5 5],[9 9 4 5.5 5.5 4],[0 3],[6 6],[0 3 8 10],[3 3 6 6])',...
'Mask Type','Logic Switch',...
'Mask Dialogue','Logic switch|Switch tolerance')
temp = 'LOGIC SWITCH Switches between inputs u2 and u3 based on logic value ';
temp = [temp 'of u1\nu1=0, y=u2; \nu1>=Tol, y=u3;'];
temp = [temp ' \n0<u1<Tol, then y is linear interplation between'];
temp = [temp ' u2 and u3.'];
set_param(blkname,'Mask Translate','Tol=@1',...
'Mask Help',temp);
if cod(1) == 0
Tol = num2str(fl(1));
else
Tol = '0';
end;
set_param(blkname,'Mask Entries',[Tol '\/'])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -