Exchanging data with other applications MathCad Help

As described earlier in this chapter, Mathcad can import and export data files in formats recognized by other applications, including data files saved in spreadsheet programs. This is useful when you simply want to connect to a data file as opposed to the application in which it was created.

For some work, however, you may need access to functionality in the other application as well as the data. It is convenient, then, to set up a link between Mathcad and the other application. A link allows you to exchange data and have immediate access to the other application from within Mathcad.

By linking an application to your Mathcad worksheet, you can:

• Send values from Mathcad to the application.
• Use the application to manipulate the data dynamically without actually leaving the Mathcad environment

Although performing tasks of all three kinds takes full advantage of the link, you can also use the link to perform just one or two of them.

To create a connection between Mathcad and another application, you’ll use an application component. (For a general discussion of components, see “Introduction to components” on page 422.) When you insert an application component into your Mathcad worksheet, you’ll actually see a small window on that application’s environment embedded in your Mathcad worksheet. When you double-click on the component, Mathcad’s menus and toolbars change to those of the other application. This gives you access to the application without leaving the Mathcad environment.

Mathcad provides components for creating links to Microsoft Excel, MathSoft’ s Axum (a data analysis and graphics application), and MAHTLAB from The MathWorks, Inc. The Scriptable Object component allows you to create a custom component to any other application using a scripting language.

The Excel component

You can use the File Read/Write component to import and export data to and from an Excel file as described in the sections “Connecting to a data file” on page 426 and “Exporting to a connected data file” on page 431. However, there may be times when you want to exchange data between an Excel file and a Mathcad worksheet, and you need brief access to the functionality in Excel, not just the data stored there. For example, you may have some values in Mathcad that you want to send to Excel, use Excel for some manipulation, and send values back to Mathcad to continue working

Inserting an Excel component

Before you insert an Excel component into a Mathcad worksheet, Excel needs to be installed on your system, but it does not need to be running.

To insert an Excel component into a Mathcad worksheet:

• Click in a blank spot in your worksheet. If you want to send values to the component from a Mathcad variable defined in your worksheet, make sure you click below or to the right of the variable definition.
• Choose Component from the Insert menu.

• Select Excel from the list and click “Next.” This launches the first part of the Excel Setup Wizard:

Inserting an Excel component

Inserting an Excel component

• If you want to connect a file you’ve already created, choose “Create from file,’ and type the path name in the text box or use the Browse button to locate the file; then click “Open.” If you don’t want to connect to a previously created file, choose “Create an empty Excel Worksheet

When you finish using the Wizard, you’ll see the Excel component in your worksheet with placeholders for the input and output variables. For example, an Excel component that will be sent one input variable and whose output will define two output variables would look like this:

1nserting an Excel component into Mathcad to exchange data

1nserting an Excel component into Mathcad to exchange data

When you click outside the component, input variables are sent to Excel from Mathcad and a range of cells are sent from Excel back to Mathcad and assigned to output variables. Once the output variables are defined, you can manipulate them however you’d like using Mathcad’s built-in functions and operators.

By default, the Excel component displays only some of the rows and columns. To see more or fewer rows and columns, double-click on the component so that you see handles along the sides of the component region. 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 component’s dimensions to change.

The MATLAB component

You can use the File Read/Write component to import and export data to and from a MATLAB file as described in the sections “Connecting to a data file” on page 426 and “Exporting to a connected data file” on page 431. However, there may be times when you want to exchange data between a MATLAB worksheet and a Mathcad worksheet, and you need brief access to MATLAB’s functionality, provided you have installed MATLAB (professional edition) on your system. For example, you may have some values in Mathcad that you want to send to MATLAB, use MATLAB to manipulate them, and send values back to MATLAB.

A MATLAB component lets you:

• Pass values stored in variables in Mathcad into MATLAB variables.

• Double-click on the MATLAB component to use MATLAB to process the data.

• Send data from MATLAB variables into Mathcad variables.

Inserting a MATLAB component

To insert a MATLAB component into a Mathcad worksheet

•Click in a blank spot in your worksheet. If you want to send values to the MATLAB component from a Mathcad variable, make sure you click below or to the right of the variable definition.
• Choose Component from the Insert menu.
• Select MATLAB from the list and click “Next.” The MATLAB component will be inserted into your worksheet.
• In the placeholder that appears at the bottom, enter the name of the Mathcad input variables to pass into the MATLAB component. In the placeholder that appears to the left of the component, enter the names of the Mathcad output variables to be defined. You can add more placeholders or remove some in the same way that you add and remove inputs and outputs for the Excel component as described in the section “Making changes to the inputs and outputs” on page 439.

The Axum component

Axum is a technical graphing and data analysis application available from MathSoft. Axum gives you access to over 75 2D and 3D graph types. You also get complete control over the look of your graphs because you can point and click to make just about any change you want

If you have Axum 5 (patch level 5.03 or higher) installed on your system, the Axum component brings some of this graphing power to your Mathcad worksheet and gives you the power to create publication-quality graphs from your Mathcad data without leaving the Mathcad environment. (For a general discussion of components, see’ “Introduction to components” on page 422.)

• Create over 50 different types of 2D and 3D graphs using Mathcad data. For example, the Axum component lets you create the following: a 2D Area Chart, a 2D Grouped Bar Chart, and a 3D Regression Plot.
• Double-click on the Axum component to use Axum to format every detail of your graph.

The Scriptable Object component

Although Mathcad has components for exchanging data between a Mathcad worksheet and Excel, MATLAB, and Axum, you can actually exchange data between a Mathcad worksheet and any other application that supports OLE Automation, even if Mathcad does not have a specific component to do so. You can use the Scriptable Object component to create a custom component that:

• Sends values from Mathcad to the application.
• Uses the application to manipulate the data without actually leaving Mathcad.
• Sends values from the other application back to Mathcad.

Inserting a Scriptable Object

To insert a Scriptable Object component into a Mathcad worksheet

This launches the Scripting Wizard. The Wizard rust prompts you to specify the OLE erver application from which you want to create a Scriptable Object. The Object to Script scrolling list shows the available applications on your system. Choose an application that supports the OLE2 automation interface (consult the documentation for the application for details).

• Whether the component will be a new file or whether you will insert a file that already exists.
• Whether you will see the actual file in your Mathcad worksheet or if you’ll see an icon.

When you click the “Next” button, the Wizard will bring you through other dialog boxes where you will specify

• Which scripting language you will use.
• The type of object you want to script.
• The name of the object.
• The number of inputs and outputs the object will accept and provide.

When you finish using the Wizard, you’ll see a Scriptable Object component in your worksheet with placeholders for the input and output variables. Enter the input variables in the bottom placeholders. Enter the output variables into the placeholders to the left of the Figure 19-6 shows a simple example of a scripted object-in this case, a picture of a face. The object accepts two input values and sends out two output values. The input values determine whether the face smiles or winks.

Posted on November 24, 2015 in Data Management

Share the Story

Back to Top
Share This