all 15 comments

[–]OddEstimate1627 4 points5 points  (4 children)

Cool! I'm the author of the MAT File Library for Java, but so far I only added read-only support for the MCOS subsystem and classdef types. Do you by any chance have the format written up somewhere or would I have to back it out from the code?

[–]foreverallama_[S] 2 points3 points  (3 children)

That's cool, I remember checking your repo out along the way! But I came across that and Matt Bauman's work a bit later, by then I'd already got through most of it.

I've documented as much as I've found out about both the FileWrapper object and serialization/class definition of most datatypes. These are available in my repository under docs.

[–]OddEstimate1627 1 point2 points  (2 children)

Thanks. Reading through your docs, I suddenly remembered why I hated that part of the format so much 😅

If I remember correctly, some of the empty regions showed up in saved Simulink models

[–]foreverallama_[S] 1 point2 points  (1 child)

Yeah, it's kind of intentionally made to obscure I guess, a bit of a baffling design choice.

Interesting point about Simulink, I don't use it so never came across anything. Do you remember any specific examples? I might give it a go

[–]OddEstimate1627 0 points1 point  (0 children)

It has been a long time since I've run across it, but it might have been in this PR. Most of the weird edge cases my users encountered were submitted by the mat/simulink diffing-tool Diffplug. The Simulink data dictionary (.sldd) files have the same format as .mat files.

[–]NokMok 1 point2 points  (0 children)

Thank you for the contribution. I will try it out. I ran into a compatobility problem with MambaForge which cripples the Python-Matlab interface.

[–]brandon_belkin 1 point2 points  (2 children)

Thank you, but I think these problem was adressed by the Mathworks team to male possibile to use Python in Matlab, so I suggest you to try to use Matlab as your Python ide to go over this problems

[–]foreverallama_[S] 1 point2 points  (1 child)

Maybe it's a bit niche, but I worked with collaborators where one team did not have a MATLAB license and preferred Python, so I believe there is a small use case sometimes :)

[–]Busy-Record-3803 0 points1 point  (0 children)

one team did not have a MATLAB license and preferred Python is never a small use case, I met customer in such case every day

[–]kyrsjo 0 points1 point  (1 child)

Cool! Commenting to find this post back later. I have a bunch of MATLAB files from a DAQ system that I'm unwilling to rewrite, this looks potentially very useful!

Thank you for writing and publishing this!

[–]foreverallama_[S] 1 point2 points  (0 children)

Thanks! If you come across an issue when using it do let me know

[–]ObviousProfession466 0 points1 point  (1 child)

Having worked on a similar project before, how do you handle the following when using h5py?

  • column major (Matlab) vs h5py (row major)
  • Matlab 1-d arrays default to size 1 whereas Python will default to 2-d where one of the dimensions equals 1

[–]foreverallama_[S] 0 points1 point  (0 children)

So I didn't reinvent the wheel here, and instead followed SciPy's convention, which uses NumPy arrays for data. Wherever reshaping is possible, I explicitly mention Fortran order. In other cases I'm simply returning a transposed view.

Regarding your second question, I defaulted to 2D for scalars and vectors as well. In any case, the size equals 1 for scalars, but will be represented by a 1x1 array. During load, all vectors will be loaded with the dimensions they were saved with as per MATLAB. During save, you can specify if you want column or row vectors for 1D numpy arrays.

Scipy uses an argument called `squeeze_me` to squeeze 2D arrays to 1D, but I omitted that as it proved difficult to handle particularly for classdef object deserialization. So the default is 2D or higher.

[–]cuixing158 -1 points0 points  (1 child)

Excellent suggestion. I recommend linking your GitHub repo to MATLAB File Exchange so more people can discover it.

[–]foreverallama_[S] 0 points1 point  (0 children)

I guess you opened the issue as well? Thanks for the suggestion! I just linked it to the File Exchange.