title: Export a neural network trained with MATLAB in other programming languages
body: <p>I trained a neural network using the MATLAB Neural Network Toolbox, and in particular using the command <code>nprtool</code>, which provides a simple GUI to use the toolbox features, and to export a <code>net</code> object containing the informations about the NN generated.</p>
  
  <p>In this way, I created a working neural network, that I can use as classifier, and a diagram representing it is the following:</p>
  
  <p><img src="https://i.stack.imgur.com/rMLho.jpg" alt="Diagram representing the Neural Network"></p>
  
  <p>There are 200 inputs, 20 neurons in the first hidden layer, and 2 neurons in the last layer that provide a bidimensional output.</p>
  
  <p>What I want to do is to use the network in some other programming language (C#, Java, ...).</p>
  
  <p>In order to solve this problem, I try to use the following code in MATLAB:</p>
  
  <pre><code>y1 = tansig(net.IW{1} * input + net.b{1});
  Results = tansig(net.LW{2} * y1 + net.b{2});
  </code></pre>
  
  <p>Assuming that <code>input</code> is a monodimensional array of 200 elements, the previous code would work if <code>net.IW{1}</code> is a 20x200 matrix (20 neurons, 200 weights).</p>
  
  <p>The problem is that I noticed that <code>size(net.IW{1})</code> returns unexpected values:</p>
  
  <pre><code>&gt;&gt; size(net.IW{1})
  
      ans =
  
      20   199
  </code></pre>
  
  <p>I got the same problem with a network with 10000 input. In this case, the result wasn't 20x10000, but something like 20x9384 (I don't remember the exact value).</p>
  
  <p>So, the question is: how can I obtain the weights of each neuron? And after that, can someone explain me how can I use them to produce the same output of MATLAB?</p>