data processing of the .mat result from Dymola simulation - matlab

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:
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?
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?

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".
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

How can I import ground truth data into Matlab for the training of a (faster) R-CNN?

I have a large, labelled, dataset which I have created and I would like to provide it to Matlab to train an R-CNN (using the faster R-CNN algorithm).
How can this be done?
The built-in labeller provided by Matlab requires that the user manually load each data sample and label it with a graphical user interface.
This is not practical for me as the set is already labelled and it contains 500,000 samples.
It should be noted, that I can control the format in which the data set is stored. So, I can create .csv files or excel files if needed.
I have tried two directions:
1. Creating a mat file, similar to the one created by the labeller.
2. Looked for ways within Matlab to import the data from .csv or excel files.
I have had no success with either methods.
For Direction 1:
Though there are many libraries that can open mat files, they are not able to open or create files similar to the Matlab ground truths because these are not simple matrices (the cells themselves contain matrices of varying dimensions that represent the bounding boxes of each classified object). Moreover, though the Matlab Level 5 file format is open source I have not been successful in using it to write my own code (C# or C++) to parse and write such files.
For Direction 2:
There are generic methods in Matlab to load .csv and excel files but I do not know how to organize these files in such a way as to produce the structure that the labeller creates and that is consumed by the fasterRCNN trainer.

Compression of large figures in .fig format in MATLAB

My MATLAB script generates a figure from a timeseries data that, when saved, is over 200 MB in size. Is there a way to compress the figure to a lesser size in '*.fig' format? The compression has to be lossless so that I can zoom in and view the details in the figure. The figure has to be saved in *.fig format so that the axis property relations between subplots are preserved and I can use the data cursor tool.
The *.fig format cannot be saved as is in compressed form. The format is just not capable of it. But in MATLAB you can use functions zip to compress files created by savefig, and unzip with passing to openfig. This way you can create simple script to load and save zipped figs. Of course you will need to use a temp file, which should be taken care of as well.

Matlab Audio Format- How to process?

I have downloaded a EEG recording of a person in Matlab-Audio Format. I have no idea of how to use it in Matlab for further processing. Is it possible to generate signals in Matlab? If so, is there any code to generate EEG signal?
Any help would be highly appreciated. Thanks in advance!
Some versions of Winamp and Microsoft Access set the description for the .mat file extension to "MATLAB Audio Format", although I have no idea what this means. It's unclear to me if such a unique file type really exists; I'd love to know more if there is actually some special format of which I am not aware. More likely, the file you downloaded is simply a standard MATLAB .mat file containing the EEG data in one or more variables. You can read the variables in MATLAB with the load command. To see the variable names contained in the MAT file prior to loading it, use whos with the -file switch.

Need a method to store a lot of data in Matlab

I've asked this before, but I feel I wasn't clear enough so I'll try again.
I am running a network simulation, and I have several hundreds output files. Each file holds the simulation's test result for different parameters.
There are 5 different parameters and 16 different tests for each simulation. I need a method to store all this information (and again, there's a lot of it) in Matlab with the purpose of plotting graphs using a script. suppose the script input is parameter_1 and test_2, so I get a graph where parameter_1 is the X axis and test_2 is the Y axis.
My problem is that I'm not quite familier to Matlab, and I need to be directed so it doesn't take me forever (I'm short on time).
How do I store this information in Matlab? I was thinking of two options:
Each output file is imported separately to a different variable (matrix)
All output files are merged to one output file and imprted together. In the resulted matrix each line is a different output file, and each column is a different test. Problem is, I don't know how to store the simulation parameters
Edit: maybe I can use a dataset?
So, I would appreciate any suggestion of how to store the information, and what functions might help me fetch the only the data I need.
If you're still looking to give matlab a try with this problem, you can iterate through all the files and import them one by one. You can create a list of the contents of a folder with the function
ls(name)
and you can import data like this:
A = importdata(filename)
if your data is in txt files, you should consider this Prev Q
A good strategy to avoid cluttering your workspace is to import them all into a single matrix. SO if you have a matrix called VAR, then VAR{1,1}.{1,1} could be where you put your test results and VAR{1,1}.{2,1} could be where you put your simulation parameters of the first file. I think that is simpler than making a data structure. Just make sure you uniformly place the information in the same indexes of the arrays. You could also organize your VAR row v col by parameter vs test.
This is more along the lines of your first suggestion
Each output file is imported separately to a different variable
(matrix)
Your second suggestion seems unnecessary since you can just iterate through your files.
You can use the command save to store your data.
It is very convenient, and can store as much data as your hard disk can bear.
The documentation is there:
http://www.mathworks.fr/help/techdoc/ref/save.html
Describe the format of text files. Because if it has a systematic format then you can use dlmread or similar commands in matlab and read the text file in a matrix. From there, you can plot easily. If you try to do it in excel, it will be much slower than reading from a text file. If speed is an issue for you, I suggest that you don't go for Excel.

How can I read a text file of image intensity values and convert to a cv::Mat?

I am working on a project that requires reading intensity values of several images from a text file that has 3 lines of file header, followed by each image. Each image consists of 15 lines of header followed by the intensity values that are arranged in 48 rows, where each row has 144 tab-delimited pixel values.
I have already created a .mat file to read these into Matlab and create a structure array for each image. I'd like to use OpenCV to track features in the image sequence.
Would it make more sense to create a .cpp file that will read the text file or use OpenCV and Matlab mex files in order to accomplish my goal?
I'd recommend writing C++ code to read the file directly independent of Matlab. This way, you don't have to mess with row major vs. column major ordering and all that jazz. Also, are there specs for the image format? If it turns out to be a reasonably common format, you may be able to find an off-the-self reader/library for it.
If you want the visualization and/or other image processing capabilities of Matlab, then mex file might be a reasonable approach.