Importing data MathCad Help

Although you can use Mathcad as a tool for working with variable and function definitions, you can also use Mathcad to perform calculations on data. In order to do so, you first need to import the data into a Mathcad worksheet using either the File ReadlWrite component or the Input Table component. For a general discussion of components see “Introduction to components” on page 422. You use these components to import data into a Mathcad array. Once the data are in Mathcad as an array, you can use any of Mathcad’s built-in functions and operators

When you import data into Mathcad you should consider where your data is stored:

• It may be stored in a file created in another application.
• It may have been copied to the clipboard from another application.
• It may be on a piece of paper in front of you.

Mathcad therefore allows you to import data by reading from a data file, by pasting it in from the clipboard, or by typing it directly into a Mathcad worksheet.

Importing data from a data file

Mathcad can import data from a file created in any of a variety of applications, such as:

• Excel (* .xls)
• Professional edition of MATLAB (*.mat)
• Lotus 1-2-3 (*.wk*)
• ASCII editors (*.dat, *.csv, *.prn, *.txt)

When you want to import data from a data file into Mathcad, you should first decide whether you want the data to update automatically in Mathcad whenever it changes later in the data file.

Connecting to a data file

To import data and establish a connection between your Mathcad worksheet and the data file, use the File ReadlWrite component

• Click in a blank spot of your worksheet.
• Choose Component from the Insert menu.
• Choose File ReadlWrite from the list and click “Next.”

This launches the first part of the File Read or Write Wizard. Choose “Read from a data source” and press “Next” to go to the second page of the Wizard, shown below

• From the File Format drop-down list in this Wizard, choose the type of data file you want to read.
• Type the path to the data file you want to read or use the “Browse” button to locate it.

Connecting to a data file

Connecting to a data file

 

Press “Finish.” You’ll see the File ReadIW rite component icon and the path to the data file. For example, if you read from a data file called data.txt, you’ll see:

Importing data from a data file. Whenever the data file changes,

Importing data from a data file. Whenever the data file changes,

You can now manipulate the Mathcad variable however you’d like using Mathcad’s built-in functions and operators. Each time you calculate the worksheet, Mathcad will re-read the data from the file you have specified.

By default, Mathcad will read in the entire data file and assign the values to a matrix with the variable name you provide. To read in only certain rows or columns of a data file:

• Click once on the component to select it.
• Click with the right mouse button on the component so that you see the context menu for the component (see example on page 424).
• Choose Properties from the context menu to bring up the Properties dialog box

Connecting to a data file

Connecting to a data file

•Use this dialog box to specify the row and columns at which to start and stop reading.
To read in a different data file or a different type of data file:
• Click with the right mouse button on the component and select Choose File from the component context menu.
• In the “Files of type” text box, choose the type of file you’d like to import. Use the dialog box to browse to the data file, select the data file, and click “Open.”

Importing once from a data file

You can use the Input Table component to import data once from a data file without establishing a connection between a Mathcad worksheet and the data file. To do so:

• Click in a blank spot of your worksheet.
• Choose Component from the Insert menu.
• Select Input Table from the list and click “Next.” The Input Table component will be inserted into your worksheet:

In the placeholder that appears to the left, enter the name of the Mathcad variable to which this data will be assigned.
• Click with the right mouse button on the component so that you see the context menu for the component (see example on page 424).
• Choose Import.
• The Read from File dialog box appears. In the “Files of type” text box, choose the type of file you’d like to import. Use the dialog box to browse to the data file and click “Open.”

The data from the data file will appear in your worksheet in a table. See Figure 19-2 for an example

When you double-click on the table, you can edit the values in it. You’ll see scroll bars which let you scroll through the table. You’ll also see handles along the sides of the component region. To resize the table, move the cursor to one of these handles so that it changes to a double-headed arrow, press and hold down the mouse button and drag the cursor in the direction you want the table’s dimensions to change.

When you click outside the component, the data is assigned as an array to the Mathcad variable you specified. You can now manipulate this Mathcad array however you’d like using Mathcad’s built-in functions and operators. Unlike the File ReadlWrite component, the Import feature of the Input Table component reads the data only when you choose Import, not each time you calculate the worksheet.

Posted on November 24, 2015 in Data Management

Share the Story

Back to Top
Share This