https://github.com/ami-iit/matio-cpp
A C++ wrapper of the matio library, with memory ownership handling, to read and write .mat files.
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (15.7%) to scientific vocabulary
Keywords
Repository
A C++ wrapper of the matio library, with memory ownership handling, to read and write .mat files.
Basic Info
- Host: GitHub
- Owner: ami-iit
- License: bsd-2-clause
- Language: C++
- Default Branch: master
- Homepage: https://ami-iit.github.io/matio-cpp/
- Size: 6.39 MB
Statistics
- Stars: 66
- Watchers: 15
- Forks: 10
- Open Issues: 5
- Releases: 10
Topics
Metadata Files
README.md
matio-cpp 
matio-cpp is a C++ wrapper for the matio library, automatically dealing with memory allocation and deallocation.
It can be used for reading and writing binary MATLAB .mat files from C++, without the need to access or rely on MATLAB's own shared libraries.
Overview
Installation
Dependencies
The depencies are CMake (minimum version 3.10) and matio. While we suggest to follow the build instructions provided in the matio home page, it can also installed from common package managers:
- Linux: sudo apt install libmatio-dev
- Linux, macOS, Windows, via conda-forge: conda install -c conda-forge libmatio
Eigen is an optional dependency. If available, some conversions are defined.
For running the tests, it is necessary to install Catch2. Where supported, valgrind can be installed to check for memory leaks.
Linux/macOS
sh
git clone https://github.com/ami-iit/matio-cpp
cd matio-cpp
mkdir build && cd build
cmake ../
make
[sudo] make install
Notice: sudo is not necessary if you specify the CMAKE_INSTALL_PREFIX. In this case it is necessary to add in the .bashrc or .bash_profile the following lines:
sh
export matioCpp_DIR=/path/where/you/installed/
Windows
With IDE build tool facilities, such as Visual Studio:
sh
git clone https://github.com/ami-iit/matio-cpp
cd matio-cpp
mkdir build && cd build
cmake ..
cmake --build . --target ALL_BUILD --config Release
cmake --build . --target INSTALL --config Release
In order to allow CMake finding matio-cpp, it is necessary that the installation folder is in the PATH.
Inclusion
matio-cpp provides native CMake support which allows the library to be easily used in CMake projects
In order to use matio-cpp in your project, add the following in your CMakeLists.txt
```cmake
find_package(matioCpp REQUIRED)
...
targetlinklibraries(yourTarget PRIVATE matioCpp::matioCpp) ```
Supported Data Types
matio-cpp can handle the following data types:
- Element, like double, int, ...
- String
- Vector, i.e. 1-dimensional arrays of primitive types
- MultiDimensionalArray, i.e. n-dimensional arrays of primitive types
- CellArray, i.e. n-dimensional arrays of generic types
- Struct, i.e. a collection of name/variable pairs
- StructArray, i.e. n-dimensional arrays of Structs
All these types can be read/written from/to .mat files.
Example of usage
Read a .mat file
```c++
include
// ...
matioCpp::File input("input.mat");
// You can check if input is open with the isOpen() method
matioCpp::CellArray cellArray = input.read("cellarray").asCellArray(); //Read a Cell Array named "cellarray"
matioCpp::Element
```
Write a .mat file
```c++
include
// ...
matioCpp::File file = matioCpp::File::Create("test.mat"); //If the file already exists, use the same cnstructor as the example above
std::vector
matioCpp::String testString("string_name"); testString = "string content"; file.write(testString);
```
It is possibile to convert common types to matioCpp types with the function matioCpp::make_variable. Examples:
```c++
std::vector
std::array
int classicalArray[] = {1, 2, 3}; auto toMatioClassic = matioCpp::makevariable("test", matioCpp::makespan(classicalArray, 3));
std::string string("something"); auto toMatioString = matioCpp::make_variable("name", string);
std::vector
auto matioDouble = matioCpp::make_variable("double", 5.0);
auto matioBool = matioCpp::make_variable("bool", true);
auto matioInt = matioCpp::make_variable("int", 2);
auto matioChar = matioCpp::make_variable("char", 'f');
std::vectorstd::string stringVector = {"Huey", "Dewey", "Louie"};
auto matioCell = matioCpp::makevariable("stringVector", stringVector);
If ``eigen`` is available, it is also possible to convert from and to ``eigen`` types:
c++
matioCpp::Vector
Eigen::VectorXd eigenVec = matioCpp::to
matioCpp::MultiDimensionalArray
Eigen::MatrixXf toEigenMatrix = matioCpp::to_eigen(matioCppMatrix);
Eigen::Matrix3f eigenMatrix;
eigenMatrix << 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0;
auto toMatioMatrix = matioCpp::makevariable("testMatrix", eigenMatrix);
Eigen::Vector3i eigenVec;
eigenVec << 2, 4, 6;
auto toMatioEigenVec = matioCpp::makevariable("testEigen", eigenVec);
It is also possible to slice a ``MultiDimensionalArray`` into an Eigen matrix:
c++
std::vector
matioCpp::MultiDimensionalArray
/* So we have a tensor of the type | 1 3 | | 5 7 | | 9 11 | | 2 4 | | 6 8 | | 10 12 | */
Eigen::MatrixXf slice1 = matioCpp::to_eigen(matioCppMatrix2, { -1, -1, 0 }; //Equivalent to the Matlab operation matioCppMatrix2(:,:,1) /* Obtain | 1 3 | | 2 4 | */
Eigen::MatrixXf slice2 = matioCpp::to_eigen(matioCppMatrix2, { 1, -1, -1 }; //Equivalent to the Matlab operation matioCppMatrix2(2,:,:) /* Obtain | 2 6 10| | 4 8 12| */
Eigen::MatrixXf slice3 = matioCpp::to_eigen(matioCppMatrix2, { -1, 0, 0 }; //Equivalent to the Matlab operation matioCppMatrix2(:,1,1)
/*
Obtain
| 1 |
| 2 |
*/
``
In the slice, the value-1` means that the entire dimension is taken.
matioCpp also exploits visit_struct to parse C++ structs into matioCpp structs. Example:
```c++
struct testStruct
{
int i{1};
double d{2.0};
std::string s{"test"};
std::vector
//----------
testStruct s; matioCpp::Struct automaticStruct = matioCpp::make_variable("testStruct", s); ```
Example
You can check the example in the example folder on how to include and use matioCpp.
Known Limitations
- Complex arrays are not yet supported
- Cannot read timeseries from a
.matfile (this is amatiolimitation https://github.com/tbeu/matio/issues/99) - Cannot read string arrays from a
.matfile (this is amatiolimitation https://github.com/tbeu/matio/issues/98) - Cannot read strings in a
Structfrom a.matfile (this is amatiolimitation related to https://github.com/tbeu/matio/issues/98)
Similar Projects
Maintainers
- Stefano Dafarra (@S-Dafarra)
Owner
- Name: Artificial and Mechanical Intelligence
- Login: ami-iit
- Kind: organization
- Location: Italy
- Website: https://ami.iit.it/
- Repositories: 111
- Profile: https://github.com/ami-iit
GitHub Events
Total
- Create event: 4
- Release event: 2
- Issues event: 7
- Watch event: 9
- Delete event: 3
- Issue comment event: 25
- Push event: 9
- Pull request review comment event: 3
- Pull request review event: 6
- Pull request event: 6
- Fork event: 1
Last Year
- Create event: 4
- Release event: 2
- Issues event: 7
- Watch event: 9
- Delete event: 3
- Issue comment event: 25
- Push event: 9
- Pull request review comment event: 3
- Pull request review event: 6
- Pull request event: 6
- Fork event: 1
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Stefano | s****a@g****m | 222 |
| Silvio Traversaro | s****o@i****t | 21 |
| serkan tan | m****n@g****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 7 months ago
All Time
- Total issues: 36
- Total pull requests: 53
- Average time to close issues: about 2 months
- Average time to close pull requests: 13 days
- Total issue authors: 14
- Total pull request authors: 4
- Average comments per issue: 4.64
- Average comments per pull request: 1.25
- Merged pull requests: 52
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 3
- Pull requests: 3
- Average time to close issues: about 23 hours
- Average time to close pull requests: about 16 hours
- Issue authors: 2
- Pull request authors: 2
- Average comments per issue: 8.0
- Average comments per pull request: 0.67
- Merged pull requests: 3
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- S-Dafarra (14)
- dptreurniet (3)
- GiulioRomualdi (3)
- traversaro (3)
- DrasLorus (2)
- zhengliuer (2)
- Nicogene (1)
- acampbel (1)
- xaltmiles (1)
- xela-95 (1)
- mannickutd (1)
- isorrentino (1)
- pascalreinhold (1)
- Chasikanaft (1)
Pull Request Authors
- S-Dafarra (44)
- traversaro (14)
- GiulioRomualdi (2)
- mserkantan (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
- Total downloads: unknown
- Total dependent packages: 2
- Total dependent repositories: 0
- Total versions: 1
conda-forge.org: libmatio-cpp
- Homepage: https://github.com/ami-iit/matio-cpp
- License: BSD-2-Clause
-
Latest release: 0.2.1
published over 3 years ago
Rankings
Dependencies
- pozil/auto-assign-issue v1 composite
- actions/cache v1 composite
- actions/checkout master composite
- actions/checkout v2 composite
- conda-incubator/setup-miniconda v2 composite
- actions/checkout master composite
- webfactory/ssh-agent v0.4.1 composite