No BSD License  

Highlights from
simbus

from simbus by Sanjai Singh
The DataBus Blockset provides a method for manipulating signals from a vector in SIMULINK.

setnout(sys,outparam)
function setnout(sys,outparam)
%SETNOUT Sets the number of outports connected to a block in a subsystem.
%
%For use only with the SIMULINK Bus connection blocks.
%
%See also SETNIN

%Copyright (c) 1995 by The MathWorks, Inc.
%$Revision: 1.1 $ $Date: 1997/02/11 20:51:44 $

Version = version;
v5 = strcmp(Version(1),'5');

% Parse the input 'outparam'.
siz = length(outparam);
if siz==1
  nout = outparam;
else
  nout = siz;
end

% Error checking.
if nout<=0
 error('Must pass SETNOUT 1 or more outputs.')
end

% What blockname to use
blkname='Demux';

% Determine whether the number of outports should be increased or decreased.
blks = get_param(sys,'blocks');
nblks = size(blks,1);

if v5
  eval('blks = strvcat(blks{:});')
end

% Find the number of outports
cnt = 0;
for i=1:nblks
   cnt = cnt + any(findstr(blks(i,:),'O'));
end

% If outports are to be added...
if nout>cnt
  % Setup the default horizontal offset
  dx=250;
  % Setup the default vertical offset
  dy=40;

  % Set the number outputs
  if v5
    set_param([sys '/' blkname],'outputs',mat2str(outparam));
  else  
    set_param([sys '/' blkname],'outputs',outparam);
  end
  % Add the blocks and lines.
  for i=(cnt+1):nout
    name = ['O' num2str(i)];
    add_block('built-in/Outport',[sys '/' name]);
    if v5    
      set_param([sys '/' name],'Port',num2str(i),'position',[dx,i*dy,dx+20,i*dy+20]);
    else    
      set_param([sys '/' name],'Port',i,'position',[dx,i*dy,dx+20,i*dy+20]);
    end    
    add_line(sys,[blkname '/' num2str(i)],[name '/1']);
  end
  % else if outports are to be deleted...
elseif nout<cnt
  % Delete the lines and blocks.
  for i=cnt:-1:(nout+1)
    name = ['O' num2str(i)];
    delete_line(sys,[blkname '/' num2str(i)],[name '/1']);
    delete_block([sys '/' name]);
  end

  % Set the number outputs
  if v5  
    set_param([sys '/' blkname],'outputs',mat2str(outparam));
  else    
    set_param([sys '/' blkname],'outputs',outparam);
  end
else
  % Set the number outputs
  if v5
    set_param([sys '/' blkname],'outputs',mat2str(outparam));
  else    
    set_param([sys '/' blkname],'outputs',outparam);
  end
end

% End.

Contact us at files@mathworks.com