data processing of the .mat result from Dymola simulation

Viewed 428

I am trying to do data processing with the .mat result from Dymola. My plan is to use MATLAB. I got a few questions about the .mat file:

  1. If I load the .mat file into MATLAB directly, the data structure is very strange, I have to use the MATLAB scripts shipped with Dymola to load the .mat file. Is there an explanation about how the data is stored in the .mat file?
  2. when plotting the diagram with the result, I wanna change the unit, but I am not sure how to make Dymola output the data with the unit I want to use. Is there any setting that allows me to change the unit when Dymola output data into the .mat file?
3 Answers

Regarding the file format, note that there is a utility to convert the MAT files to a simple HDF5-based format, if that makes post-processing easier. There are scripts for both MATLAB and Python to read such files (extension SDF).

You can get an explanation for the basic data-structure of the result file if you generate a textual result file (it might also be somewhere in the documentation), and the most relevant part is:

 Matrix with 4 columns defining the data of the signals:

 dataInfo(i,1)=    j: name i data is stored in matrix "data_j".
                      (1,1)=0, means that name(1) is used as abscissa
                      for ALL data matrices!

 dataInfo(i,2)=    k: name i data is stored in column abs(k) of matrix
                      data_j with sign(k) used as sign.

And to simplify things: there are at most two data-matrices, and the abscissa used for ALL data matrices is "Time".

  1. You cannot currently directly output mat-files in specific units. However, you can output csv-files using specific units.

The structure of the .mat files created by Modelica Dymola is introduced here briefly. But what you should know about this file format is that Dymola keeps the simulation variables in two different mat-file variables in this way:

  • The name and description for ALL of the variables are kept in two different separate variables inside the .mat file, i.e. name and description.
  • If a variable has a constant value and its value is not changed over time (like a scalar variable), it is kept inside data_1 variable inside the .mat file.
  • Otherwise, it is kept inside the data_2 variable inside the .mat file. Keeping variable data like this is a technique used my Dymola to gain the best performance while saving simulation data in large files.

For reading these mat files created by Dymola without using Dymola itself, you can use a .mat reader library like MATIO to read the data and then interpret the results by your own.

Related