Reputation: 1242
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:
Upvotes: 2
Views: 1213
Reputation: 128
I don't know if this is still interesting but I am sure at least folk coming from a search engine to this topic might be helped...
I found all these conversions and scriptings of Dymola frustrating, annoying and cumbersome (why not having an "export values" button???)!
So I wrote a simple MATLAB script that I can use whenever I find a results worth to be exported. The advantage is that I guess everybody understands what it's doing.
% Read variables from multiple Dymola result files.
clc
clear
%% Parameters
% Path to Dymola conversion tool.
path_alist = 'D:\sw\3DS\Dymola 2021x\bin64\alist.exe';
% Path to the folder containing Dymola results.
folder_dymola = '...\20_Dymola\Arbeitsordner';
% Result file names of Dymola, starred names allowed to select multiple.
filename_dymola = 'const.k = *.mat';
% Export MAT file path with all the Dymola results.
path_results = fullfile(folder_dymola, 'export_results.mat');
% Variable names to extract.
var_names = {
'model.forceGain.flange_b.f';
'model.armature.flange_a.s'
};
%% Read files and collect variables
% Find all results files.
files_result = {dir(fullfile(folder_dymola, filename_dymola)).name};
% Prepare conversion command.
cmd_1 = ['"' path_alist '" '];
for var_name = var_names'
cmd_1 = [cmd_1 '-e ' var_name{:} ' '];
end
cmd_2 = [' "' fullfile(folder_dymola, 'export.csv') '"'];
% Scan through all result files and save their content.
results = cell(length(files_result), 1);
for i = 1:length(files_result)
% Convert the result file to CSV with the requested variables.
system([cmd_1 '"' fullfile(folder_dymola, files_result{i}) '"' cmd_2]);
% Read the CSV file.
data = readmatrix(fullfile(folder_dymola, 'export.csv'));
% Save the data.
results{i} = data;
end
% Save the results.
header = ['Time' var_names'];
save(path_results, 'header', 'results');
Upvotes: 0
Reputation: 8437
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:
name
and description
.data_1
variable inside the .mat file.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.
Upvotes: 2
Reputation: 649
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).
Upvotes: 3
Reputation: 12527
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".
Upvotes: 2