title: Error due to variable size data in Matlab function block
body: <p>I have a problem that many others had before, so I read some discussions and references before asking the following:</p>
  
  <p>I have a Matlab function block in Simulink, which would like to be a modulator. It gets as input a <code>[nx1]</code> frame of data and should return a an <code>[lx1]</code> frame, where either <code>l=n</code> or <code>l = n/K</code>, for some <code>K</code> which divides <code>n</code>.</p>
  
  <p>However, the (very simplyfied extract of) code</p>
  
  <pre><code>function ak = Modulator(dataFrame,dataType)
  
        coder.varsize('ak',length(dataFrame));
  
        M = 4; % this is for simplicity in this extract
  
        if dataType == 1 %input is a binary stream, bit mapping required
                ak = zeros(round(length(dataFrame)/log2(M)),1);
        else % input data is a stream of integer
                ak = zeros(length(dataFrame),1);
        end  
  
    end
  </code></pre>
  
  <p>Doesn't compile because</p>
  
  <pre><code>"Data 'ak' is inferred as a variable size matrix,
   while its specified type is something else."
  </code></pre>
  
  <p>Now, in <code>line 2</code> I specified that it is a variable size matrix, and I also used an <code>if/else</code> constructor to initialize it.</p>
  
  <p>To make the compiler happy, one may check the <code>"Variable number of columns"</code> checkbox for <code>ak</code>, in the Data and Ports Manager, but this turns out in a new error, because the blocks in cascade don't accept variable data, at least the ones I need, like digital filters.</p>