Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
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!
Solved! Go to Solution.
Hi,
The fix is real simple.
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
Hi,
The fix is real simple.
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
Thanks Terry - that worked a treat, much appreciated!