help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Properly formatting matrices in Octave


From: Mike Miller
Subject: Re: Properly formatting matrices in Octave
Date: Mon, 4 Nov 2013 20:27:53 -0500

On Mon, Nov 4, 2013 at 10:36:05 -0800, AMG wrote:
> I want to display the values of a matrix using 2 decimal digits AND the
> numbers in columns aligned on the decimal point. So far, "format bank" gives
> me the closest output that I want, but displays the numbers in a rather
> messy way.

This might be a bug, I'm not sure what the expected result with
negative signs is in Matlab. If you believe this to be wrong, please
report it to the bug tracker

  https://savannah.gnu.org/bugs/?func=additem&group=octave

> What format or command can I use to make Octave display matrices in this
> way? (i.e. columns aligned on the decimal point using 2 decimal digits)

As a workaround, you could use the printf family of functions to
format your matrix:

  octave:1> Ua = ...
  octave:2> printf ("%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f
%6.2f\n", Ua.');
   -0.22  -0.11   0.29  -0.41  -0.11  -0.34  -0.52   0.06   0.41
   -0.20  -0.07   0.14  -0.55   0.28   0.50   0.07   0.01   0.11
   -0.24   0.04  -0.16  -0.59  -0.11  -0.25   0.30  -0.06  -0.49
   -0.40   0.06  -0.34   0.10   0.33   0.38  -0.00   0.00  -0.01
   -0.64  -0.17   0.36   0.33  -0.16  -0.21   0.17  -0.03  -0.27
   -0.27   0.11  -0.43   0.07   0.08  -0.17  -0.28   0.02   0.05
   -0.27   0.11  -0.43   0.07   0.08  -0.17  -0.28   0.02   0.05
   -0.30  -0.14   0.33   0.19   0.11   0.27  -0.03   0.02   0.17
   -0.21   0.27  -0.18  -0.03  -0.54   0.08   0.47   0.04   0.58
   -0.01   0.49   0.23   0.02   0.59  -0.39   0.29  -0.25   0.23
   -0.04   0.62   0.22   0.00  -0.07   0.11  -0.16   0.68  -0.23
   -0.03   0.45   0.14  -0.01  -0.30   0.28  -0.34  -0.68  -0.18

Notice the transpose of the matrix because the printf family of
functions operate along the columns of the argument first.

HTH,

-- 
mike


reply via email to

[Prev in Thread] Current Thread [Next in Thread]