title: Cost minimizing algorithm in MATLAB?
body: <p>I have the following problem that I need to address in MATLAB:</p>
  
  <p>I am given an n by n matrix whose sum of elements is always defined to be 1 for all n. I would like to convert my matrix, call it Matrix A, to another Matrix, call it Matrix B, whose elements also sum up to be 1. However, Matrix B will have different elements. The "cost" to move any unit is defined to be the number of horizontal and vertical movements along the matrix * the deposition. For example,</p>
  
  <pre><code>1 0 0            0.2   0    0
  0 0 0    to       0    0.3  0
  0 0 0            0.5   0    0
  </code></pre>
  
  <p>My cost is 1.6 because I have moved 0.3 2 units (1 down and 1 right) for a total cost of 0.6 and I moved 0.5 2 units down for a total cost of 1. </p>
  
  <p>I will need to do this for a 19 by 19 matrix with different entries, dispersed. How would I execute this? I understand this is a solution to the minimum cost flow problem, but I'm having difficulty implementing it in MATLAB. </p>