Accessing Origin as server application from MATLAB

This post will demonstrate using MATLAB code to connect with Origin, read data from the active worksheet in Origin,  process the data, and place the results back into the worksheet in Origin.

Procedure:

1. Download and open the OGW file( partial_least_regression_missing) in Origin and activate the first worksheet in the book. This sheet has data with missing values.

2. Launch MATLAB.  Download and run partial_least_regression_missing_value_imputation.  Missing values in the Origin worksheet will be replaced by imputed values calculated in MATLAB. All the operations in the Origin workbook template is updated if auto calculation is selected in the analysis dialog.

missing_imputation

 

 

In this example, MATLAB acts as an client application that connects with Origin. A COM object for Origin application is created, and then data is exchanged back and forth with Origin. In addition to data, commands can be sent to Origin, and methods and properties of Origin objects can also be accessed.The MATLAB code and comments for this application is listed below:

 

 

Note: If you got an error message after run MatLab script as “Undefined function ‘invoke’ for input arguments of type ‘double’.”, please clean windows registry first with the following instructions.

  1. Click your Window’s Start menu and type “regedit” and press enter to run Registry editor.
  2. Find HKEY_CURRENT_USER\SOFTWARE\OriginLab folder. Right click and delete it.
  3. After that please reopen Origin and follow the instruction of the blog again, that error should not be happen.

In case the error happens again, please clean registry and restart your computer.

4 Responses

  1. Hello,I have a question.
    The example give the property(or method), such as ‘Name’, ‘GetData’, ‘SetData’.
    And I want to set the other property, such as ‘Long name’, ‘Units’, etc.
    How can I get the property list or the grammar form?
    I have tried the ’get‘ function of matlab. It seems not working.

    • Yiming Chen

      Please try the following code to set longname, Units, etc.
      cols = invoke(wks, ‘Columns’);
      colx = invoke(cols, ‘Item’, uint8(0));
      invoke(colx, ‘Longname’, ‘Length’);
      invoke(colx, ‘Units’, ‘m’);
      More properties of column and its usage can be found in the following page:
      http://www.originlab.com/doc/COM/Classes/Column

  2. Hi, I would like to ask. I still got this error after for a few times. How should i resolve this problem?

    x = cell2mat(invoke(wks,’GetData’, 0,0,-1,-1));
    Undefined function ‘invoke’ for input arguments of type ‘double’.

    • Hello, Sorry for replying late. Here is what we found. I will also update the blog.

      If you got an error message after run MatLab script as “Undefined function ‘invoke’ for input arguments of type ‘double’.”, please clean windows registry first.
      Click your Window’s Start menu and type “regedit” and press enter to run Registry editor. Find HKEY_CURRENT_USER\SOFTWARE\OriginLab folder. Right click and delete it. After that please reopen Origin and follow the instruction of the blog again, that error should not be happen. In case the error happens again, please clean registry and restart your computer.

      Thanks, Snow

Leave a Reply