📄 sb2sl221.m
字号:
function sb2sl221(blkname,in,fl,cod,timer)
%SB2SL221 converts blocks with twice as many inputs as outputs.
% SB2SL221(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 10/2/92 -- 10/6/92
% Copyright (c) 1990-93 by The MathWorks, Inc.
% $Revision: 1.10 $ $Date: 1993/06/09 22:09:40 $
% 221 works for 5:3 4 5; 11:4; 3:6
if in(2) == 5
if in(3) == 3
temp = 'atan2(u[1],u[2])'; sh = 'atan2(u)';
elseif in(3) == 4
temp = 'sin(atan2(u[1],u[2]))'; sh = 'sin(atn(u))';
elseif in(3) == 5
temp = 'cos(atan2(u[1],u[2]))'; sh = 'cos(atn(u))';
end;
elseif in(2) == 11 & in(3) == 4
if in(in(17)+3) == 1
temp = 'u[1] ~= u[2]'; sh = '~=';
elseif in(in(17)+3) == 2
temp = 'u[1] == u[2]'; sh = '==';
elseif in(in(17)+3) == 3
temp = 'u[1] < u[2]'; sh = '<';
elseif in(in(17)+3) == 4
temp = 'u[1] <= u[2]'; sh = '<=';
elseif in(in(17)+3) == 5
temp = 'u[1] > u[2]'; sh = '>';
elseif in(in(17)+3) == 6
temp = 'u[1] >= u[2]'; sh = '>=';
end;
elseif in(2) == 11 & in(3) == 3
if in(in(17)+3) == 1
temp = 'EQ';
elseif in(in(17)+3) == 2
temp = 'NEQ';
elseif in(in(17)+3) == 3
temp = 'OR';
elseif in(in(17)+3) == 4
temp = 'NOR';
elseif in(in(17)+3) == 5
temp = 'AND';
elseif in(in(17)+3) == 6
temp = 'NAND';
elseif in(in(17)+3) == 7
temp = 'NOT';
end;
sh = temp;
end;
if in(2) == 11 & in(3) == 3 & in(4) == 1
sb2sllgc('NOT',1,blkname);
elseif in(2) == 3 & in(3) == 6
set_param([blkname '/input2'],'Port','2',...
'position',[20,80,40,100]);
set_param([blkname '/output1'],'position',[215,55,235,75])
set_param([blkname '/input1'],'position',[20,25,40,45])
add_block('built-in/S-function',[blkname '/S-function'])
set_param([blkname,'/S-function'],...
'function name','sftable2',...
'parameters','xindex, yindex, table',...
'position',[140,52,190,78])
add_block('built-in/Mux',[blkname '/Mux'])
set_param([blkname '/Mux'],'inputs','2',...
'position',[90,46,120,79])
add_line(blkname,[45,90;65,90;65,70;80,70])
add_line(blkname,[195,65;205,65])
add_line(blkname,[45,35;65,35;65,55;80,55])
add_line(blkname,[125,65;130,65])
set_param(blkname,'Mask Type','2-D Table Lookup')
temp = 'Two Dimensional Table Lookup\nThe first input corresponds to X';
temp = [temp ' Index and the second input corresponds to the Y Index|'];
temp = [temp 'X Index|Y Index|Table'];
set_param(blkname,'Mask Dialogue',temp)
set_param(blkname,'Mask Translate',...
'xindex=@1; yindex=@2; table=@3; sftab2chk(xindex,yindex,table);')
temp = 'This block returns a linearly interpolated intersection from t';
temp = [temp 'he table using the X index (which corresponds to the ro'];
temp = [temp 'ws of the table) and the Y index (which corresponds to '];
temp = [temp 'the columns of the table). Extrapolation is used.'];
set_param(blkname,'Mask Help',temp);
sh = 'plot(-10,-10,110,110,[90,50,10],[90,40,30],[90,50,10],';
sh = [sh '[50,26,20],[90,50,10],[22,13,10])'];
tmp1 = in(in(17)+4);
tmp2 = in(in(17)+5);
temp = [];
for i= 1: tmp2
temp = [temp fl((i-1)*tmp1+1:tmp1*i)];
end;
x = temp(1:tmp1-1,1)';
y = temp(tmp1,2:tmp2);
temp = temp(1:tmp1-1,2:tmp2);
[x, tmp3]=sort(x);
temp = temp(tmp3,:);
[y, tmp3]=sort(y);
temp = temp(:,tmp3);
if length([mat2str(x) '\/' mat2str(y) '\/' mat2str(temp) '\/']) <= 255
% directly set it up
set_param(blkname,'Mask Entries',...
[mat2str(x) '\/' mat2str(y) '\/' mat2str(temp) '\/'])
else
% have to save as a variable
load sb2sltmp
app = sb2slbnm(blkname);
tmp1 = ['O' num2str(xn+1) app]; tmp2 = ['O' num2str(xn+2) app];
tmp3 = ['O' num2str(xn+3) app];
eval([tmp1 '= x;']);
appsave('sb2sltmp', tmp1, x);
disp([tmp1 ' is used as x-index of 2D look up table in ' blkname])
eval([tmp2 '= y;']);
appsave('sb2sltmp', tmp2, y);
disp([tmp2 ' is used as y-index of 2D look up table in ' blkname])
eval([tmp3 '= temp;']);
appsave('sb2sltmp', tmp3, temp);
disp([tmp3 ' is used as table content of 2D look up table in ' blkname])
% xs=[xs tmp1 tmp2 tmp3];
xn=xn+3;
appsave('sb2sltmp', 'xn', xn);
%eval(xs)
set_param(blkname,'Mask Entries',...
[tmp1 '\/' tmp2 '\/' tmp3 '\/'])
end;
else
for i=1:in(5)
add_block('built-in/Mux',[blkname '/Mux' num2str(i)]);
set_param([blkname '/Mux' num2str(i)], 'inputs',num2str(in(4)/in(5)),...
'position',[160,(55+in(4)/in(5)*12)*i-40,190,55*i+in(4)/in(5)*12*(i+1)-30]);
for j=1:in(4)/in(5) %MI case,
set_param([blkname '/input' num2str(i+(j-1)*in(5))],...
'Port',num2str(i+(j-1)*in(5)),...
'position',[25+rem((j-1),3)*25,(55+in(4)/in(5)*12)*i+(j-1)*12-40,...
45+rem((j-1),3)*25,(55+in(4)/in(5)*12)*i+(j-1)*12-20]);
autoline(blkname,['input' num2str(i+(j-1)*in(5)) '/1'],...
['Mux' num2str(i) '/' num2str(j)]);
end;
if in(2) == 11 & in(3) == 3
add_block('built-in/Combinatorial Logic',[blkname '/Fcn',num2str(i)]);
sb2sllgc(temp,in(4)/in(5),[blkname '/Fcn' num2str(i)]);
else
add_block('built-in/Fcn',[blkname '/Fcn', num2str(i)]);
set_param([blkname '/Fcn' num2str(i)],'Expr',temp);
end;
set_param([blkname '/Fcn' num2str(i)],...
'position',[240,55*i+in(4)/in(5)*12*(i+1/2)-55,365,55*i+in(4)/in(5)*12*(i+1/2)-15]);
set_param([blkname '/output' num2str(i)],'Port',num2str(i),...
'position',[380,55*i+in(4)/in(5)*12*(i+1/2)-45,400,55*i+in(4)/in(5)*12*(i+1/2)-25]);
autoline(blkname,['Mux' num2str(i) '/1'],['Fcn' num2str(i) '/1']);
autoline(blkname,['Fcn' num2str(i) '/1'], ['output' num2str(i) '/1']);
end;
end;
set_param(blkname,'Mask Display',sh)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -