title: MATLAB: Printing a formatted table
body: <p>I'm working on an iteration program on MATLAB (Jacobi iteration method on solving A <strong>x</strong> = <strong>b</strong> ), which allows me to make N iterations.</p>
  
  <p>So far, I can code the iteration, but I want to improve the presentation of the results.</p>
  
  <p>My program's output:</p>
  
  <pre><code>jacobi(A, b, 20);  %N = 20 iterations
  </code></pre>
  
  <p>Values of <code>x</code> by columns of iteration(s) (starting at 0) from left to right:</p>
  
  <pre><code>X =
  </code></pre>
  
  <p>Columns 1 through 9</p>
  
  <pre><code>     0    3.4000   -0.0556    1.3848    1.0250    0.9300    1.0558    0.9813    1.0034
       0    4.0000    0.8603    2.1810    2.0329    1.9030    2.0453    1.9826    1.9997
       0    2.5000    4.5444    2.1023    3.3195    2.9782    2.9513    3.0402    2.9831
       0    2.0000    5.3463    3.5175    4.0772    4.0612    3.9463    4.0266    3.9939
       0    6.7778    3.8111    5.4106    4.9648    4.9366    5.0513    4.9777    5.0046
  </code></pre>
  
  <p>Columns 10 through 18</p>
  
  <pre><code>1.0026    0.9979    1.0011    0.9998    1.0000    1.0001    1.0000    1.0000    1.0000
  2.0027    1.9977    2.0008    1.9998    1.9999    2.0001    2.0000    2.0000    2.0000
  3.0035    3.0013    2.9984    3.0009    2.9998    3.0000    3.0001    3.0000    3.0000
  3.9990    4.0022    3.9988    4.0004    4.0000    3.9999    4.0001    4.0000    4.0000
  5.0015    4.9979    5.0011    4.9997    5.0000    5.0001    5.0000    5.0000    5.0000
  </code></pre>
  
  <p>Columns 19 through 21</p>
  
  <pre><code>1.0000    1.0000    1.0000
  2.0000    2.0000    2.0000
  3.0000    3.0000    3.0000
  4.0000    4.0000    4.0000
  5.0000    5.0000    5.0000
  </code></pre>
  
  <p>Nevermind if you guys never heard of such method, but I'm wondering, if I were to insert strings such that it becomes</p>
  
  <pre><code>jacobi(A, b, 20);
  </code></pre>
  
  <p>Values of x by columns of iteration(s) (starting at 0) from left to right:</p>
  
  <p>X =</p>
  
  <p>Columns 1 through 9</p>
  
  <pre><code>   iteration
       ----------------------------------------------------------------------------------
        0  |    1   |    2    |    3    |    4    |    5    |    6    |    7    |     8
       ----------------------------------------------------------------------------------
        0    3.4000   -0.0556    1.3848    1.0250    0.9300    1.0558    0.9813    1.0034
        0    4.0000    0.8603    2.1810    2.0329    1.9030    2.0453    1.9826    1.9997
        0    2.5000    4.5444    2.1023    3.3195    2.9782    2.9513    3.0402    2.9831
        0    2.0000    5.3463    3.5175    4.0772    4.0612    3.9463    4.0266    3.9939
        0    6.7778    3.8111    5.4106    4.9648    4.9366    5.0513    4.9777    5.0046
  </code></pre>
  
  <p>and so on, how exactly do I do that?</p>
  
  <p>I'm thinking of inserting <code>------ up</code>, <code>i  |</code> middle, and <code>------</code> below and number of iterations in the loop to let it generate as many as N desired.</p>
  
  <p>So far, the closest example I've found on searches, is </p>
  
  <pre><code>arrayfun(@(x)sprintf('Hole %j',x), 1:18)','UniformOutput',false)
  </code></pre>
  
  <p>But still, I can't figure out how to incorporate this idea into my code. Is this kind of output possible in MATLAB?</p>
  
  <p>Can anyone help me? Thanks in advance.</p>
  
  <p>I'm taking a course on MATLAB, but with just a couple of months of lessons, there's not much stuffs I have learned yet. But I'm looking for a challenge.</p>