Many of Mathcad’s built-in functions and operators are useful for manipulating sets of data. Mathcad therefore provides special mechanisms for importing various types of data into a Mathcad worksheet. And, once you’ve worked with the data, Mathcad allows you to export the results you’ve generated.
This chapter also discusses a group of Mathcad functions for reading and writing ASCII text files containing numerical data. These functions are primarily available for compatibility with Mathcad worksheets created in earlier versions of Mathcad.
This chapter contains the following sections:
Introduction to components
Overview of components, specialized OLE objects used for managing data in Mathcad.
Using the File ReadlWrite component and the Input Table component to import data from a data file. Using the Input Table component to type data in manually or paste it in from the clipboard.
Using the File ReadlWrite component and the Output Table component to export data to a data file or to the clipboard.
Exchanging data with other applications
Using the Excel, MATLAB, and Axum components to create links between a Mathcad worksheet and these computational applications. Using the Scriptable Object component to script a custom component.
Functions for reading and writing ASCII data files
Description of ASCII file access functions for reading and writing structured and unstructured data.
Introduction to components
Mathcad provides components to exchange data between Mathcad and other applications. A component is a specialized OLE object that you insert into a Mathcad worksheet to create a link between the worksheet and either a data source or another application containing data. Unlike other OLE objects you insert into a worksheet, a component communicates with the mathematical equations in Mathcad, linking your Mathcad computations to the rest of your computing environment. This link allows data to flow dynamically between the Mathcad worksheet and a data source or application.
The following components are available in Mathcad for exchanging data between a Mathcad worksheet and other data sources or applications:
• File Read/Write, for importing and exporting data files in a variety of formats.
• Input Table and Output Table, for quickly getting data in and out of a Mathcad worksheet.
• Axum, for creating Axum graphs in a Mathcad worksheet.
• Excel, for creating a link between a Mathcad worksheet and an Excel file.
• MA TLAB, for creating a link between a Mathcad worksheet and a MAHTLAB file.
• Scriptable Object, for creating a custom component via a scripting language.
How to work with components
The basic steps to inserting a component in order to exchange data with Mathcad are as follows:
• Insert the component.
• Specify the input variable(s) and output variable(s).
• Configure the component so that it knows what to do with input and what to send as output.
Step 1: Inserting a component
To insert a component into a Mathcad worksheet:
• Click in a blank spot of your Mathcad worksheet where you would like the component.
• Choose Component from the Insert menu.
• Choose one of the components from the list and click “Next.”
Depending on the component you choose, you may see a Wizard dialog box which lets you specify some properties of the component before it is inserted. Pressing the “Next” buttons continues through the Wizard. You can use the “Back” buttons to go back to a previous page. When you click the “Finish” button, the component will be inserted into your worksheet.
If you don’t see a Wizard when you choose one of the components from the Insert Component dialog box, you’ll immediately see the component, with some default properties, inserted into your worksheet.
Each component has its own look, so you will see something different for each component you choose. All components have one or more placeholders either to the right of the := or at the bottom of the component. For example, the Excel component might look like this when inserted into your worksheet:
The placeholders you see to the left of the := are for the output variables which will contain the data passed from the component. The placeholder at the bottom of the component is for the name of an input variable the component is getting from Mathcad.
The number of placeholders you see to the left or the bottom depend either on the default properties for the component or on the settings you provided in the component’s Wizard.
Step 2: Configuring a component
Once you’ve inserted a component into a worksheet, you usually need to set up the component’s properties so that the component knows how to handle any inputs it’s getting from Mathcad and what to send as output. To configure the properties for a component
• Click on the component once to select it.
• Click on it with the right mouse button to see a context menu, like the one shown below for the File ReadlWrite component. The options on the context menu depend on the component you selected, but usually you’ll see the commands Cut, Copy, and Properties. Other options are specific to each component.
• Choose Properties from the context menu
The settings in the Properties dialog box depend on the component you clicked on. The properties dialog for the Output Table component, for example, lets you specify the display format for the numbers in the table. The properties dialog for the Excel component in Mathcad Professional lets you specify the cells in which the input values are stored and the cells from which the output is sent.
Step 3: Exchanging data
Once you’ve inserted a component into a Mathcad worksheet, filled in the appropriate placeholders, and configured the properties, click away from the component region. At that point, the data exchange takes place: data will pass from the input variable into the component, and the output variable will become defined with the output. This will happen whenever you click on the component and press [F9], when the input variables change, or when you choose Calculate Worksheet from the Math menu
The components available in Mathcad are used to connect a Mathcad worksheet to other data sources and applications. If you want to connect these data sources and applications to each other as well as to Mathcad, you can use the MathConnex application if you have Mathcad Professional.
In addition to the components available in Mathcad Professional, MathConnex contains a number of other components for manipulating data, such as a Mathcad component for connecting to a Mathcad worksheet. The MathConnex environment lets you connect any of one of the available components to any other component. MathConnex is therefore a tool for controlling data as it flows from one data source or application to another. You can visually design systems of data flow to analyze projects which involve a variety of applications and data sources.
To run MathConnex, click on the MathConnex icon from the Mathcad toolbar, or exit Mathcad and run MathConnex as you would any application. For more information, refer to the MathConnex Getting Started Guide.