title: Could not determine the size of this expression
body: <p>I have resently started to use MATLAB Simulink, and my problem is that i can't implement an AMDF function, because simulink compiler cannot determine the lengths.</p>
  
  <p>Simulink errors:
  <br>|---------------------------------------------------------------------------------------
  <br>
  Could not determine the size of this expression.</p>
  
  <p>Function 'Embedded MATLAB Function2' (#38.728.741), line 33, column 32:
  "1:flength-k+1"</p>
  
  <p>Errors occurred during parsing of Embedded MATLAB function 'Embedded MATLAB
  Function2'(#38) </p>
  
  <p>Embedded MATLAB Interface Error: Errors occurred during parsing of Embedded MATLAB function 'Embedded MATLAB Function2'(#38) .<br>
  |---------------------------------------------------------------------------------------</p>
  
  <p><br></p>
  
  <p>MY CODE: <br>
  |---------------------------------------------------------------------------------------
  
  <pre><code>function [voiced,minAMDF] = bnrDisAMDF(frame,fs,lvlThr,fspan)&lt;br&gt;
  &lt;br&gt;
  persistent sLength&lt;br&gt;
  persistent fLength&lt;br&gt;
  persistent amdf&lt;br&gt;
  
  % Length of the frame&lt;br&gt;
  flength = length(frame);&lt;br&gt;
  
  % Pitch period is between 2.5 ms and 19.5 ms for LPC-10 algorithm&lt;br&gt;
  % This because this algorithm assumes the frequencyspan is 50 and 400 Hz
  pH = ceil((1/min(fspan))*fs);&lt;br&gt;
  if(pH &gt; flength)&lt;br&gt;
      pH = flength;&lt;br&gt;
  end;&lt;br&gt;
  &lt;br&gt;
  pL = ceil((1/max(fspan))*fs);&lt;br&gt;
  if(pL &lt;= 0 || pL &gt;= flength)&lt;br&gt;
      pL = 0;&lt;br&gt;
  end;&lt;br&gt;
  &lt;br&gt;
  sLength = pH - pL;&lt;br&gt;
  &lt;br&gt;
  % Normalize the frame&lt;br&gt;
  frame = frame/max(max(abs(frame)));&lt;br&gt;
  &lt;br&gt;
  % Allocating memory for the calculation of the amdf&lt;br&gt;
  %amdf = zeros(1,sLength); %%%%%%%%&lt;br&gt;
  amdf = 0;&lt;br&gt;
  &lt;br&gt;
  % Calculating the AMDF with unbiased normalizing&lt;br&gt;
  for k = (pL+1):pH&lt;br&gt;
      amdf(k-pL) = sum(abs(frame(1:flength-k+1) - frame(k:flength)))/(flength-k+1);&lt;br&gt;
  end;&lt;br&gt;
  &lt;br&gt;
  % Output of the AMDF&lt;br&gt;
  if(min(amdf) &lt; lvlThr)&lt;br&gt;
      voiced = 1;&lt;br&gt;
  else&lt;br&gt;
      voiced = 0;&lt;br&gt;
  end;&lt;br&gt;
  &lt;br&gt;
  % Output of the minimum of the amdf&lt;br&gt;
  minAMDF = min(amdf);&lt;br&gt;
  </code></pre>
  
  <p><br>|----------------------------------------------------------------------------------------<br>
  HELP</p>
  
  <p>Kind regards</p>
  
  <p>Søren</p>