cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Mathcad Prime 9.0 API - Interfacing with MATLAB, extracting value from matrix

HMM
4-Participant
4-Participant

Mathcad Prime 9.0 API - Interfacing with MATLAB, extracting value from matrix

Hi,

 

I'm new to Mathcad Prime, having used 15 for a while now. I've been looking with interest at the API offered with Mathcad Prime, and I have had some luck in recreating some of the various PTC examples in MATLAB using 

 

actxserver("MathcadPrime.Application")

 

 to link the Mathcad COM server to MATLAB.

Where I'm encountering issues is extracting values from a matrix. Using the test.mcdx file provided with the VBScript example, I can retrieve the value of output1 successfully, however I'm struggling to do the same with matrixOutput1.

I'm using the following to load the matrix:

 

prime = actxserver("MathcadPrime.Application"); %%Open a COM session for Mathcad
prime.Activate; %Focus the Mathcad window (not necessary unless you want to see what happens)

dir = "C:\[...]\test.mcdx";    %Path of worksheet to open

ws = prime.Open(dir);   %Open the worksheet and create an object to represent 

matrix = ws.OutputGetMatrixValue("out_0")

 

When I query the rows and columns using matrix..matrixResult.Rows the expected value of 3 is returned.

However, matrix.MatrixResult.GetMatrixElement(0,1) returns 0, as do all other elements.

Has anyone else been successful in extracting data from Mathcad matrices to MATLAB in this way?

I'm looking to avoid the alternative method of some sort of intermediary file (.mat, .m, .csv etc).

 

Many thanks for any help you can offer!

1 ACCEPTED SOLUTION

Accepted Solutions

Hi,

The fix is real simple.

Capture.JPG

Element (1,1) is 7.2.

matrix.MatrixResult.GetMatrixElement(1,1) returns 0.

0 is the return code of the function.  0 represents a good call

simply add in the variable for the value returned to the left hand side of call

[rc b]= matrix.MatrixResult.GetMatrixElement(1,1) returns 0, and 7.2

 

 

Total calls to get the value shown below:

 

>> h=actxserver("MathcadPrime.Application")

h =

	COM.MathcadPrime_Application


>> h.Activate

>> dir="D:\Prime\ReadThis1.mcdx"

dir = 

    "D:\Prime\ReadThis1.mcdx"

>> ws=h.Open(dir)

ws =

	Interface.PTC_Mathcad_Prime_COM_Automation_IMathcadPrimeWorksheet3

>> matrix=ws.OutputGetMatrixValue('out1')

matrix =

	Interface.A3C56254_B233_48CD_86F7_5D8CE19A7097

>> [rc b]=matrix.MatrixResult.GetMatrixElement(1,1)

rc =

     0


b =

    7.2000

 

View solution in original post

2 REPLIES 2

Hi,

The fix is real simple.

Capture.JPG

Element (1,1) is 7.2.

matrix.MatrixResult.GetMatrixElement(1,1) returns 0.

0 is the return code of the function.  0 represents a good call

simply add in the variable for the value returned to the left hand side of call

[rc b]= matrix.MatrixResult.GetMatrixElement(1,1) returns 0, and 7.2

 

 

Total calls to get the value shown below:

 

>> h=actxserver("MathcadPrime.Application")

h =

	COM.MathcadPrime_Application


>> h.Activate

>> dir="D:\Prime\ReadThis1.mcdx"

dir = 

    "D:\Prime\ReadThis1.mcdx"

>> ws=h.Open(dir)

ws =

	Interface.PTC_Mathcad_Prime_COM_Automation_IMathcadPrimeWorksheet3

>> matrix=ws.OutputGetMatrixValue('out1')

matrix =

	Interface.A3C56254_B233_48CD_86F7_5D8CE19A7097

>> [rc b]=matrix.MatrixResult.GetMatrixElement(1,1)

rc =

     0


b =

    7.2000

 

HMM
4-Participant
4-Participant
(To:terryhendicott)

Thanks Terry - that worked a treat, much appreciated!

Top Tags