title: Creating a MIMO (multiple input multiple output) transfer function system without hardcoding the number of inputs and outputs
body: <p><strong>Introduction</strong><br>
  As part of a larger system I'm trying to create a multiple input multiple output transfer function that only links inputs to outputs on the lead diagonal*. I.e. it has non zero transfer functions between input 1 and output 1, input 2 and output 2 etc etc. </p>
  
  <p>*whether you really count that as a MIMO system is a fair comment, I want it in this format because it links to a larger system that really is MIMO.</p>
  
  <p><strong>Hard Coding</strong><br>
  I can achieve this by concatenating transfer functions as so</p>
  
  <pre><code>tf1=tf([1 -1],[1 1]);
  tf2=tf([1 2],[1 4 5]);
  tf3=tf([1 2],[5 4 1]);
  
  G=[tf1 0 0; 0 tf2 0; 0 0 tf3]; 
  </code></pre>
  
  <p>Which works fine, but (a) hard codes the number of inputs/outputs and (b) becomes increasingly horrible the more inputs and outputs you have.</p>
  
  <p><strong>Diag function</strong><br>
  This problem seemed perfect for the diag function however diag does not seem to be defined for type 'tf'</p>
  
  <pre><code>G=diag([tf1, tf2, tf3])
  ??? Undefined function or method 'diag' for input arguments of type 'tf'.
  </code></pre>
  
  <p><strong>Manual Matrix manipulation</strong><br>
  I also tried manually manipulating a matrix (not that I was really expecting it to work)</p>
  
  <pre><code>G=zeros(3);
  G(1,1)=tf1;
  G(2,2)=tf2;
  G(3,3)=tf3;
  ??? The following error occurred converting from tf to double:
  Error using ==&gt; double
  Conversion to double from tf is not possible.
  </code></pre>
  
  <p><strong>tf's direct to MIMO format</strong><br>
  tf also has a format in which all the numerators and denominators are represented seperately and a MIMO system is directly created. I attempted to use this in a non hard coded format</p>
  
  <pre><code>numerators=diag({[1 -1], [1 2],[1 2]})
  denominators=diag({[1 1], [1 4 5],[5 4 1]})
  G=tf( numerators , denominators )
  ??? Error using ==&gt; checkNumDenData at 19
  Numerators and denominators must be specified as non empty row vectors.
  </code></pre>
  
  <p>This one <em>almost</em> worked, unfortunately numerators and denominators are empty on the off diagonal rather than being 0; leading to the error</p>
  
  <p><strong>Question</strong><br>
  Is it possible to create a MIMO system from transfer functions without "hard coding" the number of inputs and outputs</p>