title: How to write S-function with variable size of output signal?
body: <p>I want to write a block, which sends all image files from selected directory.</p>
  
  <p>Images are of different sizes, so output signal size should vary.</p>
  
  <p>Unfortunately I was unable to find a way to change signal size at each step. There are many of undocumented features here, in examples like</p>
  
  <pre><code>block.OutputPort(1).DimensionsMode = 'Variable';
  </code></pre>
  
  <p>and</p>
  
  <pre><code>block.OutputPort(1).CurrentDimensions = [1 block.InputPort(1).Data];
  </code></pre>
  
  <p>and so on. I was unable to deduce correct way to operate all this stuff yet...</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>For example, this S-function </p>
  
  <pre><code>function Test_SF_01(block)
  % Level-2 MATLAB file S-Function.
  
      setup(block);
  
  function setup(block)
  
      % Register number of ports and parameters
      block.NumInputPorts  = 0;
      block.NumOutputPorts = 1;
      block.NumDialogPrms  = 0;
  
      % Setup functional port properties to dynamically inherited
      block.SetPreCompOutPortInfoToDynamic;
  
      % Register the properties of the output port
      block.OutputPort(1).DimensionsMode = 'Variable';
      block.OutputPort(1).SamplingMode   = 'Sample';
  
      % Register sample times
      %  [-1, 0] : Inherited sample time
      block.SampleTimes = [-1 0];
  
      % Register methods called at run-time
      block.RegBlockMethod('Outputs', @Outputs);
  
  function Outputs(block)
      block.OutputPort(1).CurrentDimensions =  floor(rand(1,2)*10)+1;
  </code></pre>
  
  <p>causes an error</p>
  
  <blockquote>
    <p>Invalid variable dimensions assignment for output port 1 of
    'Test_01/Level-2 MATLAB S-Function'. The number of variable dimensions
    is 1. However, the length of the MATLAB array is 2</p>
  </blockquote>
  
  <p>why?</p>