How to pretty print a matrix in Octave?
Asked Answered
C

1

1

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
Cheep answered 25/4, 2019 at 10:2 Comment(0)
S
3

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
Spiculum answered 25/4, 2019 at 10:38 Comment(7)
There's also the dataframe packageMucker
@TasosPapastylianou Yeah, super crappy documentation as usual! What is the function called in that package?Cheep
@m304 So that's where it went! These are only 2 of a great number of packages that are so poorly documented! Look at the link to the function. It's a blank page. No wonder Octave never took off as a useful product, even if free.Cheep
@Cheep no need for rudeness. I'm not referring to a 'function'. The dataframe package provides the dataframe object. Simple as that. When you display a dataframe it displays its row and column labels. I won't try to defend package documentation per se, but dataframe in particular is extremely well documented. As for the prettyprint function, it could be a bit more documented, and generally I'm the first to rant about proper documentation, but, honestly, in this case, prettyprint(mat, rlabels, clabels) is as self-explanatory as it gets ...Mucker
@Cheep also, I don't have a stake in octave development, but as an independent observer, your assessment of octave not having taken off is wildly off in my experience. And that's even excluding the obvious example of the most popular course on coursera relying exclusively on octave (admittedly, a good percentage of the questions ending up at SO for octave).Mucker
@TasosPapastylianou Well like you, I am also moving from Matlab to Octave, but the fact remains that clicking the prettyprint link in this answer, you get a blank page saying: this prints matrices with row and column labels. That is certainly not considered proper documentation. Regarding the package name you provided, there is nothing related to pretty print in there, so how is anyone supposed to guess how that is done? Almost every single function in the package datatframe says: Not documented.Cheep
Let us continue this discussion in chat.Mucker

© 2022 - 2024 — McMap. All rights reserved.