简体   繁体   中英

How to pretty print a matrix in Octave?

I want to create a pretty printed table from a matrix (or column vector). For Matlab there are several available functions that can do this (such as printmat, array2table , and table ), but for Octave I cannot find any.

So instead of:

>> a = rand(3,2)*10;
>> round(a)
ans =

    2   10
    1    3
    2    1

I would like to see:

>> a = rand(3,2)*10;
>> pretty_print(round(a))

   THIS   THAT
R1    2   10
R2    1   3
R3    2   1

How can I produce a pretty printed table from a matrix?
(Any available package to do so?)


UPDATE

After trying to follow the extremely obtuse package installation instruction from Octave Wiki, I kept getting the error pkg: failed to read package 'econometrics-1.1.1.tar.gz': Couldn't resolve host name . Apparently the windows version isn't able to use the direct installation command (as given on their Wiki). The only way I managed to get it, was by first downloading the package manually into the current working directory of Octave. (See pwd output.) Only then did the install command work.

pkg install econometrics-1.1.1.tar.gz
pkg load econometrics

Yes, there is a prettyprint function in the econometrics package. Once the package is installed and loaded, you can use it like this:

>> a = rand(3,2)*10;
>> prettyprint(round(a),['R1';'R2';'R3'],['THIS';'THAT'])

          THIS        THAT
R1       2.000       3.000
R2       3.000       4.000
R3      10.000       3.000

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM