Documentation Center

  • Trial Software
  • Product Updates

output::tableForm

Printing objects in table form

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

output::tableForm(obj, <separator>, options)

Description

output::tableForm(obj) prints the elements of the given object obj in table form.

The width of the table and the number of columns depends on the size of TEXTWIDTH (see options Width and Columns). The width of a column depends on the widest entry in this column.

output::tableForm determines the number of columns, that the total width of the table fits into TEXTWIDTH.

The columns are separated by one space by default.

If separator is given, then it is printed between each column (instead of one space). Appending spaces to the separator results additionally space between columns. By default the separator is one space.

If the first argument obj is a table or a domain, output::tableForm uses the option Columns = 2 (two columns) and the separator "= " as default.

Without the option Sort the objects are converted to strings and then sorted alphabetically. To avoid any sorting the option Sort = FALSE must be given.

Examples

Example 1

For all examples on this page we assume the TEXTWIDTH 75:

TEXTWIDTH := 75:

Print some random numbers in table form:

SEED := -1:
output::tableForm([random(100000)() $ k = 1..30])
11647 12826 26280 26292 28315 30908 36523 42073 4682  47334 52640 56426
5829 615   62580 65904 66223 6719  69451 69903 77904 78221 80528 81013
86068 89016 90516 91008 92791 9532                                     

Some random strings are created. The columns should have all the same width (Unique) and be printed centered. The strings should not be sorted:

output::tableForm([_concat("*" $ random(10)()) $ k = 1..20],
                  Unique, Center, Sort = FALSE)
 "********"  "******"   "*********" "********"      "*"     "******"
"*********"   "*****"     "****"    "********"    "****"    "*****"
"*********"  "*******"   "*******"   "******"      "**"     "****"

The option Unquoted prevents printing of quotes (see fprint):

output::tableForm([_concat("*" $ random(10)()) $ k = 1..20],
                  Unique, Center, Sort = FALSE, Unquoted)
********    *      ******   ******    ****    ******     **    **
  *****     *       ****     ****      **    ******** *******  **
    *    *******                                                       

Example 2

The next object is a MuPAD® table and should be printed as a table with two columns. The table contains some random numbers and their sum of the digits:

SEED := -1:
T :=  table(op(map([random(100000000)() $ k = 1..10],
                   proc(X)
                     local Xs, k;
                   begin
                     Xs := expr2text(X);
                     X = _plus(text2expr(substring(Xs, k))
                               $ k = 1..length(Xs))
                   end_proc))):
output::tableForm(T)
19962580 = 40
25878221 = 35
37777904 = 44
41281013 = 20
43856426 = 38
46169451 = 36
66926292 = 42
80330908 = 31
89306719 = 43
94386068 = 44

Domains are also printed in this form by default:

output::tableForm(newDomain("Test",
                            table("type" = "Test",
                                  "info" = "only a testdomain")))
"info" = "only a testdomain"
"key" = "Test"
"type" = "Test"

Example 3

The next table should consist of four columns:

SEED := -1:
output::tableForm([random(100000)() $ k = 1..30], Columns = 4)
11647 12826 26280 26292
28315 30908 36523 42073
4682 47334 52640 56426
5829 615   62580 65904
66223 6719  69451 69903
77904 78221 80528 81013
86068 89016 90516 91008
92791 9532             

The next table should have a maximal width of 50 characters:

SEED := -1:
output::tableForm([random(100000)() $ k = 1..30], Width = 50)
11647 12826 26280 26292 28315 30908 36523 42073
4682 47334 52640 56426 5829  615   62580 65904
66223 6719  69451 69903 77904 78221 80528 81013
86068 89016 90516 91008 92791 9532             
delete T:

Example 4

The next examples show different usage of separators. First one single separator:

SEED := -1:
output::tableForm([random(100000)() $ k = 1..30], "|")
11647|12826|26280|26292|28315|30908|36523|42073|4682 |47334|52640|56426
5829|615  |62580|65904|66223|6719 |69451|69903|77904|78221|80528|81013
86068|89016|90516|91008|92791|9532                                     

Now a list with a separator character between each column. If the list is too short, the characters are used from beginning of the list again etc.:

SEED := -1:
output::tableForm([random(100000)() $ k = 1..30], ["|", " ", " "])
11647|12826 26280 26292|28315 30908 36523|42073 4682  47334|52640 56426
5829|615   62580 65904|66223 6719  69451|69903 77904 78221|80528 81013
86068|89016 90516 91008|92791 9532                                     

Only the first both colunms should be separated by a vertical line:

SEED := -1:
output::tableForm([random(100000)() $ k = 1..30], ["|", " " $ 10])
11647|12826 26280 26292 28315 30908 36523 42073 4682  47334 52640 56426
5829|615   62580 65904 66223 6719  69451 69903 77904 78221 80528 81013
86068|89016 90516 91008 92791 9532                                     

Additionally a character can be appended to each entry:

SEED := -1:
output::tableForm([random(100000)() $ k = 1..30],
                  ["|", " " $ 10], Append = ",")
11647,|12826, 26280, 26292, 28315, 30908, 36523, 42073, 4682,  47334, 52640,
56426,|5829,  615,   62580, 65904, 66223, 6719,  69451, 69903, 77904, 78221,
80528,|81013, 86068, 89016, 90516, 91008, 92791, 9532,                      

Example 5

The next examples show different usage of sorting. Without the option Sort the numbers are sorted as strings in lexicographical order:

SEED := -1:
output::tableForm([random(100000)() $ k = 1..30])
11647 12826 26280 26292 28315 30908 36523 42073 4682  47334 52640 56426
5829 615   62580 65904 66223 6719  69451 69903 77904 78221 80528 81013
86068 89016 90516 91008 92791 9532                                     

Sort = FALSE avoids any sorting:

SEED := -1:
output::tableForm([random(100000)() $ k = 1..30], Sort = FALSE)
30908 6719  26292 56426 81013 69451 77904 78221 86068 62580 47334 12826
9532 5829  28315 65904 42073 80528 4682  52640 69903 92791 36523 26280
89016 91008 615   66223 90516 11647                                    

Any sorting can be done with a special defined procedure, e.g., sort the numbers in reverse order:

SEED := -1:
output::tableForm([random(100000)() $ k = 1..30],
                  Sort = ((X,Y) -> Y < X))
92791 91008 90516 89016 86068 81013 80528 78221 77904 69903 69451 66223
65904 62580 56426 52640 47334 42073 36523 30908 28315 26292 26280 12826
11647 9532  6719  5829  4682  615                                      

At last a user defined procedure is given that sorts the numbers by the sum of their digits ascending:

SEED := -1:
output::tableForm([random(100000)() $ k = 1..30],
                  Sort = proc(X,Y)
                           local crossfoot;
                         begin
                           crossfoot :=
                             proc(X)
                               local Xs, k;
                             begin
                               Xs := expr2text(X);
                               _plus(text2expr(substring(Xs, k))
                                     $ k = 1..length(Xs))
                             end_proc;
                           crossfoot(X) < crossfoot(Y)
                         end_proc)
615  81013 42073 52640 91008 26280 36523 11647 12826 66223 9532 28315
30908 4682  78221 26292 90516 47334 62580 56426 80528 6719  5829 65904
89016 69451 77904 69903 92791 86068                                   

Parameters

obj

A list, set or table of any MuPAD objects or a domain

separator

A string between columns

Options

Unquoted

Strings are printed without quotes

The output function fprint is called with the option Unquoted.

Unique

All columns are of the same width

All columns are printed with the same width, the widest column determines the width of each column.

Width

Option, specified as Width = w

The maximal width of the table is set to w (instead of TEXTWIDTH). w must be a positive integer.

Columns

Option, specified as Columns = c

The number of columns is set to c. The width of the table depends on the width of any column.

    Note:   output::tableForm called with this option takes not care about the value of TEXTWIDTH.

c must be a positive integer.

Center, Left, Right

The entries of each column are aligned left-justified, centered or justified.

Sort

Option, specified as Sort = procedure

The entries are sorted with the given procedure. Entries can be printed unsorted, when procedure is the object FALSE.

Output

Option, specified as Output = file

Output into a file. If file is a string, a file named file is opened and overwritten and closed after writing. If file is a file descriptor (the return value of fopen), the table is appended to file without closing file.

String

Return as a string that can be printed

The string contains line breaks, and can be printed with print or fprint and option Unquoted.

Append

Option, specified as Append = string

Character string is appended to each entry of the list

Return Values

Void object null()

See Also

MuPAD Functions

Was this topic helpful?