How to pretty print a matrix in Octave?

三世轮回 提交于 2019-12-24 06:38:10

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/55846664/how-to-pretty-print-a-matrix-in-octave

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!