What is alternative code for 'table' function?

Hello everyone.I am a new learner.
I want to make a table with these variables;
But table function isn’t implemented in octave.Then I tried this code
Table={‘Names’,‘Ages’,‘Gender’};
Names={‘Serena’;‘John’;‘William’;‘Diana’};
Ages=[28;36;47;16];
Gender={‘Female’;‘Male’;‘Male’;‘Female’};


“Table” is described like this and I can’t change it.What are your suggestions?Thank you.

You can make use of the “tablicious” package

From the Octave command window install it with

pkg install https://github.com/apjanke/octave-tablicious/releases/download/v0.3.5/tablicious-0.3.5.tar.gz

Then you can easily create the desired output:

pkg load tablicious

Table = {'Names','Ages','Gender'};
Names = {'Serena';'John';'William';'Diana'};
Ages = [28;36;47;16];
Gender = {'Female';'Male';'Male';'Female'};

tab = table (Names, Ages, Gender);
prettyprint (tab)

Output:

---------------------------
| Names   | Ages | Gender |
---------------------------
| Serena  | 28   | Female |
| John    | 36   | Male   |
| William | 47   | Male   |
| Diana   | 16   | Female |
---------------------------
1 Like

Thank you so much.I tried and it worked.
But why did we use prettyprint instead of display or fprintf?

That is great it works for you :slightly_smiling_face: The tabilicious package aims to be Matlab compatible, but the maintainer @apjanke decided (unintentionally) for this behavior of his package. Maybe you can discuss his development decisions here with him https://github.com/apjanke/octave-tablicious/issues.

1 Like

Thank you soo much :slightly_smiling_face:

I chose “prettyprint” because it’s a function you have to call explicitly. “display” or “disp” are called automatically when you just let an array be displayed at the command window. Since table arrays can often get pretty big (at least in the ways I use them), having them print their entire contents can really spam the command window output. So I chose to have “display” do a more compact format summarizing the table’s structure, and have a separate “prettyprint” that you can call to see full details. (This was an intentional deviation from Matlab’s table behavior, because I find the default behavior of printing the full contents to be really inconvenient.)

I don’t think “fprintf” would be the right choice here: fprintf is a global function, and as far as I know, neither Octave nor Matlab have established mechanisms for user-defined objects or table arrays to be passed to fprintf conversion specifiers, or for objects to override fprintf in a standard way. So I didn’t want to stake out that behavior space in ways that might be incompatible with future changes to fprintf’s specification.

1 Like

I face the same problem. I have installed that package but after implementing that example code I got error: ‘peelOffNameValueOptions’ for this line:

tab = table (Names, Ages, Gender);

what should I do?

Can you post the exact code you entered to obtain the error? The example above does not error for me.
In the meantime, there has been a new release of the tablicious package:

pkg install https://github.com/apjanke/octave-tablicious/releases/download/v0.3.6/tablicious-0.3.6.tar.gz

I got all error loading after writing this command, even I can’t upload any picture in this comment section. Would you mind giving me your mail address? Then I could give you a screenshot.

Somewhat unrelated to the original question, but I see this mysterious error:

octave:1> pkg load tablicious
octave:2> type table
error: type: couldn't open '' for reading
error: called from
    type at line 92 column 9
octave:3> 

@dasergatskov: That might be due to bug #49434, which returns “built-in function” for classdef m-file.

1 Like

Please be precise, what is “this” command? What errors showed up?

Can you try to upload the picture again? However if it is a screenshot of code or command-window output, please copy and paste it into a fenced code block:

```
Paste Octave output here :)
```

I want this type of table

But with your same code, I am getting this output

tab = table (cycle, days, beginning, r_demand, demand, ending, shortage, order, r_lead_time, arrive);
prettyprint (tab)

Thanks for uploading the screenshots. What you want is much clearer now, but from the output it is impossible to guess how you processed the data (are those column or row vectors, for example). The problem lies too often in the detail :sweat:

Can you upload your code and the data you try to display here?

That might be due to bug #49434, which returns “built-in function” for classdef m-file .

Yep, that looks like the one. I don’t think there’s anything Tablicious as a package can do about this, because Octave’s internals/builtins/whatever are taking priority.