title: Simulink, How does this m-code block work while having input mismatch?
body: <p>In MATLAB  Simulink, I added an MPC (Model predictive control block).</p>
  
  <p>I looked inside this block:</p>
  
  <p><a href="https://i.stack.imgur.com/vzcTR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vzcTR.png" alt="mpc1"></a></p>
  
  <p>Inside it there is a wrapper subsystem called <code>MPC</code>.  I opened this one via double click:</p>
  
  <p><a href="https://i.stack.imgur.com/EQj8b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EQj8b.png" alt="mpc2"></a></p>
  
  <p>The main block inside this subsystem is <code>optimizer</code>. This block is a m-code block starting with this header:</p>
  
  <pre><code>function [xk1, u, cost, useq, status, xest, iAout] = fcn(...
              xk, old_u, ym, ref, md, umin, umax, ymin, ymax, switch_in, ext_mv, MVtarget, isQP, nx, nu, ny, degrees, Hinv, Kx, Ku1, Kut, Kr, Kv, Mlim, ...
              Mx, Mu1, Mv, z_degrees, utarget, p, uoff, voff, yoff, maxiter, nxQP, openloopflag, ...
              lims_inport, no_umin, no_umax, no_ymin, no_ymax, switch_inport, no_switch, enable_value, ...
              return_cost, H, return_sequence, Linv, Ac, ...
              ywt, uwt, duwt, rhoeps, iA, ...
              no_ywt, no_uwt, no_duwt, no_rhoeps,...
              Wy, Wdu, Jm, SuJm, Su1, Sx, Hv, Wu, I1, ...
              A, Bu, Bv, C, Dv, Mrows, nCC, Ecc, Fcc, Scc, Gcc, ...
              nv, no_md, no_ref, no_uref, no_mv, Rscale, MDscale, myindex, ...
              myoff, xoff, CustomEstimation, M, L)
  %#codegen
  coder.extrinsic('mpcblock_optimizer_double_mex');
  coder.extrinsic('mpcblock_optimizer_single_mex');
  coder.extrinsic('mpcblock_refmd_double_mex');
  coder.extrinsic('mpcblock_refmd_single_mex');
  </code></pre>
  
  <p>My question is that why the number of inputs of the function in the code is much higher than the number of inputs ports of this block in simulink. Where are these variables generated? For example how is argument <code>H</code> created before this function is called?</p>
  
  <p>Here the Simulink file is attached:</p>
  
  <p><a href="https://www.dropbox.com/s/vx67urpkt9qki9e/simulink.zip?dl=0" rel="nofollow noreferrer">https://www.dropbox.com/s/vx67urpkt9qki9e/simulink.zip?dl=0</a></p>