25.3 MATLAB Console

Video Image.png See more related video:Importing and Connecting with MATLAB

The "MATLAB Console" tool allows Origin users to issue MATLAB commands from within the Origin environment, and transfer data between the two applications either using a graphical interface, or by issuing commands.

  • The Console requires both Origin and MATLAB be installed on the same computer.
  • Origin also supports importing MATLAB (MAT) files from disk. There are two import routines, the older Data: Import from File and the new Connector-based Data : Connect to File: MATLAB. Importing MAT files does not require MATLAB to be installed.


To start the MATLAB console tool, select Connectivity: MATLAB Console from the Origin menu. A dialog will open asking if you want to connect to the existing MATLAB session.

  • If yes, follow the prompted steps to issue the appropriate command in MATLAB to make the session a shared one and then reconnect to it.
  • If no, a new instance of the MATLAB application will be launched. You can issue the "desktop" command in the console to make the new MATLAB instance visible.
MATLAB Console.png

The Import Button

The Import button in the top right corner of this dialog brings up the MATLAB Import Dialog. This dialog lists all variables in the current MATLAB workspace. You can select a single variable, or use SHIFT + select to select multiple variables, and import them into Origin. Note that when importing, you can either bring the data into a worksheet, or into a matrix. Check box options allow you to update existing Origin matrices, and to add imported data to existing Origin worksheets.

The Export Button

The Export button in the top right corner of this dialog brings up the MATLAB Export Dialog. This dialog lists all variables in the current Origin project. User can assign a name for the variable in MATLAB using the Name column, then select desired Origin worksheet columns or matrices, and transfer the selected Origin data to MATLAB.

Console Commands

In addition to using the import and export dialogs to interactively transfer data between the two applications, Origin also provides a set of commands that can be typed in the console window to perform data transfer. The following table lists available commands:

Command Syntax

Description

gr matName1 matName2 ...

Get real matrices named matName1, matName2, etc. from MATLAB.

New matrix windows of the same name are created in Origin. Existing windows of the same name are overwritten.

gc matName1 matName2...

Get complex matrices named matName1, matName2, etc. from MATLAB. New matrix windows, for real and complex components, are created in Origin. Existing windows of the same name are overwritten.

pr matName1 matName2...

Put real matrices named matName1, matName2 etc. from Origin to MATLAB. Existing windows of the same name are overwritten.

pc matName1 matName2

Put complex matrices named matName1, matName2 etc. from Origin to MATLAB. Existing windows of the same name are overwritten.

pwr wkbkrange marray

Transfer real data from Origin workbook range wkbkrange, to MATLAB array named marray.

Note that wkbkrange should be a valid Origin range such as col(index), [book1]sheet1!col(name) etc.

pwc wkbkrange marray

Transfer complex data from Origin workbook range wkbkrange, to MATLAB array named marray.

Note that wkbkrange should be a valid Origin range such as col(index), [book1]sheet1!col(name) etc.

pws wkbkrange marray

Transfer strings from Origin workbook range wkbkrange, to MATLAB array named marray.

Note that wkbkrange should be a valid Origin range such as col(index), [book1]sheet1!col(name) etc.

gwkspace

gwkspace m

Get all MATLAB variables and place them in multiple matrix sheets and objects in a new matrix window in Origin

gwkspace w

Get all MATLAB variables and place them in multiple worksheets sheets in a new workbook window in Origin

Note: The \Samples\COM Server and Client\MATLAB subfolder contains an example (CreatePlotInOrigin.m, CreatePlotInOrigin.OPJ) that illustrates how to connect to an Origin COM server from a MATLAB client (requires MATLAB).