Reputation: 23
To save the time, I'm trying to read the .mat
file rather than simulate the model again.
I used scipy.io.loadmat
but it didn't work well:
res = loadmat('ChatteringControl_result.mat')
res.keys()
['Aclass', 'dataInfo', 'name', 'data_2', 'data_1', 'description']
The keys are not variable names, and I don't know how to get the variable values.
Then I searched for resolutions, and found DyMat, it works well for other variables but cannot get time
.
res1 = DyMat.DyMatFile('ChatteringControl_result.mat')
T = res1['T']
t = res1['time']
KeyError: 'time'
So, how can I get all the results in JModelica?(Without open Matlab of course.)Like, a built-in function in JModelica?
BIG THANKS!
Upvotes: 2
Views: 556
Reputation: 1123
To load the mat file using JModelica you can use this code:
from pyfmi.common.io import ResultDymolaBinary
res = ResultDymolaBinary("MyResult.mat")
var = res.get_variable_data("myVar")
var.t #Time trajectory
var.x #Variable trajectory
Upvotes: 3
Reputation: 3523
https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/technical_details.html#the-matv4-result-file-format describes the format. I think you can also look in a Dymola manual for more details.
As for DyMat, there is no reason to get the time trajectory because you typically lookup what value a variable has at a certain time. The start and stop-times are in the data_1 matrix as far as I remember (or typically get it from the first trajectory in the data_2 matrix). (The data_2 matrix may be interpolated, so the time values stored in it may not reflect the actual steps taken internally by the solvers)
Upvotes: 3