File Exchange

image thumbnail

modelicaImport

version 1.1.0.0 (11.8 KB) by Felix
Parses a Modelica result file into a nested tree structure in Matlab

6 Downloads

Updated 23 May 2018

View License

This function parses a Modelica result file (*.mat) into a tree structue so that all variables can be accessed the same way as in Modelica.
The path to the result file has to be provided. The user can also pass a regular expression to the function to limit the return variables.
The output is a nested structure where all variables can be accessed via dot-notation. Arrays of objects in Modelica are parsed into arrays in Matlab.
res = modelicaImport(path, regex);
eg. res.object.subObject.variable
eg. res.object.subobject(1).variable
This function is pretty much a byproduct of a simulation project I did for university - I hope that is is useful. I have used this function with OpenModelica 1.9.1+dev (r22052) and Dymola 2015.

Comments and Ratings (9)

Whynot2

It worked like a charm. The resulting structure is the same you may find in your Modelica IDE.

Thanks a lot, this solved the problem! I have found another small bug when reading out the combiTable1D data from OpenModelica. Your code only reads out the y-values of the table data twice, but not the input data. I have checked the raw data from OpenModelica and the values are there in data_1. Can you please fix this? Best regards, Markus

Felix

Hey Markus,

there was a problem, when modelica left out some fields in object arrays. I uploaded an updated version, that can handle this.

I hope, this solves your problem.

Best
Felix

Hello, i use this function to import some data from openmodelica to matlab, unfortunately it sometimes crashes and generates no output at all, depending on the input file and regex parameters. I am not really familiar with matlab so i cannot fix the problem on my own. Can someone please help me to fix the problems? Following two errors it can generate:
* Subscripted assignment between dissimilar structures.
* Error using cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.

File:https://drive.google.com/file/d/1fB45L_5cXxL3JV2OXlOp7V6xEZryzW8u/view?usp=sharing

Many thanks in advance!

Felix

Hey Armando,

I never needed this myself, but I remember that there was another package here on the file exchange that provides this functionality.

You can find it here: https://de.mathworks.com/matlabcentral/fileexchange/20120-openmodelica-matlab-interface

Best
Felix

hi, do you know some way how i can run Modelica from matlab?

Updates

1.1.0.0

Resolved a bug with array parsing.

MATLAB Release Compatibility
Created with R2016b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor