![]() |
|
Tutorial 6. Working with Data TablesIn this tutorial, we will learn about manipulating data tables, using the Formula Editor, setting up 2D grids, and generating a data table from a data sequence. It is recommended that you read the topics Data Table, Data Sequence, Column and Cell Formulas, and 2D Grids before continue. Editing Data Table Start the DataScene program and create an empty project. Add an empty data
table by selecting the Add To Project...: Empty Data Table menu
command on the Project menu or by clicking the
Press down and hold the left mouse button on the column header of Column 3 (the cell with the text "Column 3") , drag the mouse pointer to include the column header of Column 4 (the cell with the text "Column 4") and then release the left mouse button. This selects Column 3 and Column 4. Right click on the column header of Column 3 or Column 4 to open the context menu (which is also the Data menu of the Application Menus). Select the Delete Columns menu command and press the Yes button on the confirmation message box. Column 3 and Column 4 are then deleted from Table1. Right click on any location inside the Table1 document window to open the context menu again and then select the Undo menu command. DataScene reverses the last column deletion and adds Column 3 and Column 4 back to Table1.
Fig. 1. Selection of Column 3 and Column 4 of Table1.
Right click on the column header of Column 4 to select Column 4 and open the context menu. Select the Insert command to open the Number of Columns dialog box. Accept the default value of 1 and press the OK button of the dialog box. A new column is added into Table1 and is named Column 5. Please note how the contents of the context menu change as the selection state of Table1 changes. Move the mouse pointer into the cell of row 1 and column 1, type text "1" in this cell. Note a pen icon appears on the row header of the first row indicating this row is in the editing mode. Move the mouse pointer into the cell of row 2 and column 2. The pen icon on the first row disappears indicating the end of the editing mode for the first row. Type text "2" into the cell of row 2 and column 2. Note that a new row, row 3, is automatically added to the table with a star displayed on its row header indicating that it is a new buffer row. Move the mouse pointer into the cell of row 3 and column 3 and type text "3". Select the cell of row 1 and column 1 by left clicking inside it exactly one time. While pressing down and holding the Ctrl key, left click inside the cell of row 2 and column 2 - which adds the cell to the cell selection. Do the same to add the cell of row 3 and column 3 into the selection. Table1 should like look that shown in Fig. 2. With the three cells selected, right click inside one of them to open the context menu. On the context menu, select the Copy menu command. Move the mouse pointer into the cell of row 1 and column 4 by left clicking inside it exactly one time. With the new cell selected, right click inside it to open the context menu and then select the Paste menu command. DataScene inserts a new column so as to preserve the spatial structure of the copied content.
Fig. 2. Selection of three cells in Table1.
Row editing operations such as row selection, deletion, and insertion operations are preformed pretty much in the same way as the column equivalents. You may want to experiment with these operations. Using the Formula Editor The Formula Editor is an important component embedded inside several dialog boxes. In this section, we will demonstrate the use of the Formula Editor in the Column/Cell Formula dialog box to prepare data for a data table. Right click the header of Column 1 of Table1 to select it and open the context menu. In the context menu, select the Set Formula menu command to open the Column/Cell Formula dialog box. In the Formula Editor group box, select Variables & Parameters in the Library Mode combo-box. DataScene displays built-in variables and parameters in the Library list box. Double click the built-in variable Row to insert it into the Formula text box. Note that when an item is selected in the Library list box, a short description is displayed in the Description text box. Append " - 1" to the formula in the Formula text box so that it reads "Row - 1". Move the mouse pointer into the To row text box of the dialog box and change its value to "100". Click the OK button to close the dialog box and apply the formula to Column 1. DataScene evaluates the formula and populates Column 1 with the evaluated values. Now open the Column/Cell Formula dialog box for Column 2. With Functions selected in the Library Mode combo-box, double click SIN() in the Library list box to insert it into the formula. Double click CELL() to insert it into the argument list of the SIN() function so that the formula now reads "SIN(CELL())". If you read the descriptions for the CELL() function then you will know that you need to supply it with three arguments. Select Tables & Columns in the Library Mode combo-box. DataScene puts all table name and column name pairs in the Library list box. Double click "Table1", "Column 1" in the Library list box to insert it into the Cell() function argument list. Append ", Row" to the argument list so that the formula reads "SIN(CELL("Table1", "Column 1", Row))". Note that you do not need to use the Library Mode combo-box and the Library list box once you are familiar with the library. Now edit the formula in the Formula textbox so that it reads "SIN[ CELL("Table1", "Column 1", Row) / (2 * PI) ]". Note that we have changed the outmost parentheses to a pair of square brackets and input a few spaces to make the formula more readable. The "PI" symbol in the formula is the Archimedes' constant and can be selected from the library when it is the Constants library mode. Click the OK button to close the dialog box and apply the formula for Column 2. Alternately, in this simple example, we could also use the simplified formula "SIN[COL(1) / (2 * PI) ]" to achieve the same results. The Col() function is similar to the Cell() function but is different in that it takes only a column index as its sole argument and thus can not be used to get values of cells in another data table.
Fig. 3. Setting up formula for Column 2.
Now plot a Line series with Column 1 as its Position component and Column 2 as it Value component. You get a line plot of the function y = sin(x/2p) in the range of [0, 99].
Fig. 4. Line series plotted using Column 1 and Column 2 of Table1.
2D Grids In this section, we will demonstrate how to draw a parabola Surface series and a parabola Triangle Surface series. These two series require the input data built on 2D grids: a rectangular grid for the Surface series and a circular grid for the Triangle Surface series. Add an empty table to the previous project. DataScene names it Table2. Select Column 1 and Column 2 of Table2 and right click on one of the column headers to open the context menu. Select the Setup 2D Grid: Rectangular Grid menu command to open the 2D Rectangular Grid dialog box. On the dialog box, change the Start Value of both the X Grid and Z Grid to -10; change the Steps of both the X Grid and Z Grid to 20. Click the OK button to close the dialog box and set up a rectangular grid on Column 1 and Column 2 of Table2. Right click the header of Column 3 to open the context menu and then select the Set Formula menu command. In the Column/Cell Formula dialog box, type "CELL("Table2", "Column 1", Row) ^ 2 + CELL("Table2", "Column 2", Row) ^ 2" into the Formula text box and then click the OK button to close the dialog box and apply the column formula to Column 3. Plot a Surface series with Table2 using Column 1 as the Position component, Column 3 as the Value component, and Column 2 as the Depth component, respectively.
Fig. 5 A parabola Surface series is drawn with data built on a rectangular grid.
Add another empty data table Table3 to the project. Select Column 1 and Column 2 of Table3 and open the context menu. On the context menu, select the Setup 2D Grid: Circular Grid menu command to open the 2D Circular Grid dialog box. Change the Steps of both the Radical Grid and Angular Grid to 20. Click the OK button to close the dialog box and set up a circular grid on Column 1 and Column 2 of Table3. Apply the column formula "CELL("Table3", "Column 1", Row) ^ 2 + CELL("Table3", "Column 2", Row) ^ 2" to Column 3 of Table3. Plot a Triangle Surface series with Table3 using Column 1 as the Position component, Column 3 as the Value component, and Column 2 as the Depth component, respectively.
Fig. 6 A parabola Triangle Surface series is drawn with data built on a circular grid.
Generating a Data Table from a Data Sequence A data table can be generated from a data sequence. This is useful, for example, if you want to use the data in the sequence to draw a Water Fall series. We will demonstrate this in the following example. Open \Examples\Animation\CH_IR_Spectrum.dts under the DataScene installation folder (which can be opened by selecting the Help: Demo Projects menu command). With the data sequence selected as the active document, select the Sequence To Table menu command on the context menu to open the Generate Table From Sequence dialog box. In the Index Selection Criterion group box of the dialog box, type "IDX % 20 = 0" into the Formula text box - which will select the 0th, 20th, 40th, ... data tables in the data sequence for table generation; in the Index Conversion group box, type "IDX * 3 + 1" into the Formula text box - which will convert the indices of the selected tables into values that will be copied into a new column of the generated data table. Click the OK button to close the dialog box. A new data table named Table1(From Sequence) is generated using the data in the selected data tables in the data sequence, an new column, Column 3, is created to contain the data generated from the second formula. Select Table1(From Sequence) as the active document, plot a Water Fall series with Column 1, Column 2, and Column 3 associated with the Position, Value, and Depth components, respectively. After some customizations, the graph looks like that shown in Fig. 7.
Fig. 7. A Water Fall series plotted using the generated data table.
Close all open projects without saving them.
See Also
|
| Home | Products | Purchase | Downloads | Gallery | Support | Company| Site Map |
| © 2008 2009 CyberWit, Inc. All rights reserved. |