Data Table Component - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Document Tools : Embedded Components : DataTableComponent

Data Table Component

Insert a one- or two-dimensional data table in a Standard Maple worksheet or document.

 

Description

Using the Data Table

Component Palette Image

DataTable Properties

Data Table Example

Data Tables in Maple

Description

• 

The data table component performs an action or a series of actions to communicate with other embedded components when the data table is updated, although assigning an action to a component is not required.

• 

The data structure used to store the data is an rtable.

• 

You can insert this embedded component from the Components palette.

• 

There are three ways to populate the data table with entries:

1. 

By referencing the name of an existing Matrix, Array, Vector, or other rtable

2. 

By filling in the initial values interactively

3. 

By importing the initial values from a file

Associating the data table with an existing Matrix

If you have already defined a Matrix, Array, Vector, or other rtable in your document, you can associate the data table with that rtable.  The rtable must be assigned to a name.

To associate the data table with an existing Matrix:

1. 

Insert the Data Table Component from the Components palette.

2. 

Select Use existing Matrix.

3. 

Select the name of the rtable from the drop-down list.

Filling in data table values interactively

To fill the initial values interactively: 

1. 

Insert a Data Table Component.

2. 

Select Create new Matrix and specify a variable name for the rtable.

3. 

Specify the total number of rows and columns of the rtable.

4. 

Set other properties, as desired, and then click OK.  The component is inserted in the document with initial values of 0.

5. 

Double-click each table cell to edit the value.

Importing data table values from a file

To import the initial values from a file:

1. 

Insert a Data Table Component.

2. 

Select Import Matrix and specify a variable name for the rtable.

3. 

Click OK.

The Data Import Assistant dialog opens. This dialog is an interactive interface that allows you to import data into Maple.

4. 

In the Data Import Assistant dialog, browse to the location of the file you want to import data from, select the file, and then click Next.

Note: The following file formats are supported: Excel®, MATLAB®, Image, Audio, Matrix Market, Comma Separated Values, and Delimited

5. 

Set the appropriate import options for your data and, optionally, preview your data within the Data Import Assistant dialog.

6. 

Click Done to close the Data Import Assistant and import the data into the Data Table Component.

Using the Data Table

• 

To perform an action when the data table is updated, click the data table, and then, from the Data Table context panel, select Edit Content Changed Code to open the Code Editor dialog for the data table. Enter the commands you want to perform in the Code Editor dialog. For more information, see the Data Table Example on this page.

• 

The data table component is customized by setting options in the Data Table context panel. To display the Data Table context panel, click the data table component. Actions are associated with components using routines in the DocumentTools package.

• 

The column widths can be set interactively by dragging the column boundaries or programmatically as described in the DataTable Properties section below.

• 

The Component Name property is used to reference the data table when using the routines from the DocumentTools package.

• 

The data table is always associated with a Matrix (or Array).  When you modify that Matrix, the data table is updated.  See Example 2.

• 

To force an update of the data table, use DocumentTools[SetProperty]("DataTable0",update), where DataTable0 is the name of your data table.

Component Palette Image

DataTable Properties

• 

The following table describes the control and use of the data table component options.

  

An x in the Get column indicates that the option can be read, that is, retrieved by using the DocumentTools[GetProperty] tool.

  

An x in the Set column indicates that the option can be written, that is, set by using the DocumentTools[SetProperty] tool.

  

 

Option

Get

Set

Option Type

columnHeader

x

x

true or false

columnNames

x

x

list of strings

columnWidths

 

x

list of integers

editable

x

x

true or false

enabled

x

x

true or false

rowHeader

x

x

true or false

rowNames

x

x

list of strings

tooltip

x

x

string

type

x

 

string

variableName

x

x

name

visible

x

x

true or false

visibleColumns

x

x

positive integer

visibleRows

x

x

positive integer

  

 

  

columnHeader

  

Specifies if the names for the columns of the table are visible.

  

columnNames

  

Specify names for the columns of the table.

  

columnWidths

  

Specify widths (in pixels) for the columns of the table. The column widths have to specified as a list. For example:

  

SetProperty("DataTable0",columnWidths, [20, 20, 20, 20]);

  

editable

  

Indicates whether the table cells are editable. By default, the value is true.

  

enabled

  

Indicates whether the data table component is enabled. If enabled is set to false, it is not possible to interactively modify elements in the data table and the data table will not receive updates when the Matrix, Vector, or Array assigned to the variable changes. In other words, it will be a snapshot in time that will not be updated. By default, the value is true.

  

rowHeader

  

Specifies if the names for the rows of the table are visible.

  

rowNames

  

Specify names for the rows of the table.

  

tooltip

  

The text that appears when the user hovers the mouse over the data table.

  

type 

  

The type of the component. This returns "DataTable".

  

variableName

  

The variable that the data table is associated with. This may be a previously defined variable that has a Matrix, Vector, or Array assigned to it, or it may be a new variable that was created when the data table was created.

  

visible

  

Specifies if the data table is visible. By default, the value is true.

  

visibleColumns

  

The number of visible columns in the data table.

  

visibleRows

  

The number of visible rows in the data table.

Data Table Example

Note: To interact with the examples provided below, open this help page as a worksheet and then execute the worksheet.

Example 1 - Create a function table and then plot the values

This example uses a DataTable component to display a set of points on a Plot component.

To insert the DataTable and Plot components using the Components palette:

1. 

Click on the DataTable icon in the Components palette.

2. 

In the Create Data Table dialog:

• 

Select Create new Matrix

• 

Set Total Columns and Visible Columns to 2

• 

Set Total Rows and Visible Rows to 7

• 

Click OK to close the Create Data Table dialog

Note: To change Row Name and Column Name, click the data table and make the changes in the Data Table context panel.

3. 

From the context panel for the data table, next to Column Name click Edit. Use Tab to highlight each entry and change the names to x and y.

4. 

Click on the Plot icon in the Components palette to insert the component.

For information on displaying the Maple palettes, see the Show Palettes help page.

 

To display the points in data table on the Plot component:

1. 

Click the DataTable component, and then from the Data Table context panel, select Edit Content Changed Code.

This launches the Code Editor.

2. 

Before the end use; statement in the dialog, enter the following command:

SetProperty("Plot0", value, plots:-pointplot(eval(parse(GetProperty("DataTable0", variableName))), color=red));

Note: Ensure the names of the components are correct (that is, that they match the Name fields of their components).

3. 

Click  or from the File menu, select Save Code to accept all changes.

4. 

From the File menu, select Close Code Editor.

5. 

Enter the points in the data table (use Tab to go to the next cell).  In this example, the points are for y= x2.  When done, press Enter to generate a display on the Plot component.

 

 

Note: You can also use the data table to display points on a 3-D plot.

To do that:

• 

 Create a data table with 3 columns instead of 2.

• 

 In the code editor for data table, write the following command instead:

SetProperty("Plot0", value, plots:-pointplot3d(eval(parse(GetProperty("DataTable0", variableName))), color=red));

  

 

  

You can verify the syntax of the embedded component action by executing these commands in the worksheet in which you have defined the embedded components.

with(DocumentTools):

MyData:= eval(parse(GetProperty("DataTable0",variableName)));

Error, (in DocumentTools:-GetProperty) Attempted to retrieve property of unknown component DataTable0. |lib/DocumentTools/src/GetProperty.mm:45|

SetProperty("Plot0", value, plots:-pointplot(eval(parse(GetProperty("DataTable0", 'variableName'))), 'color'=red));

Error, (in DocumentTools:-GetProperty) Attempted to retrieve property of unknown component DataTable0. |lib/DocumentTools/src/GetProperty.mm:45|

Example 2 - Using a Data Table to Display an Array

In this example, we first define an array.  Then we display that array in a data table.  Because the data table is linked to the array, you can then retreive or change entries easily.

1. 

Define an array and assign it the name A.  Type
A:=Array(1..8,1..4,(i,j)->i*j):
This defines an 8 by 4 array and initializes each entry using a formula: the (i,j)th entry is i*j.

2. 

Click on the DataTable icon in the Components palette.

3. 

In the Create Data Table dialog:

• 

Select Use existing Matrix

• 

If there is more than one Matrix, select A from the drop-down list.

• 

Click OK.

The data table is inserted into the worksheet.

4. 

Remove the headers: from the context panel for the data table, clear the check boxes for Show Row Header and Show Column Header.

AArray1..8,1..4,i,jij:

5. 

To retrieve a value, type A[2,4];

6. 

To change a value, type A[2,4]:=0;

The (2,4)th entry in the data table is now zero.

A2,4;

8

(5.2.1)

A2,40;

A2,40

(5.2.2)

Data Tables in Maple

Data tables in Maple are used in a number of places.  For example, you can opt to embed a probability table into the worksheet, in which case the result is displayed in a data table.  See Student[Statistics][ProbabilityTable].

See Also

DocumentTools

DocumentTools[GetProperty]

DocumentTools[SetProperty]

EmbeddedComponents

Import