Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to read .mat files in Go?

Tags:

go

mat-file

I'd like to load a MATLAB file that stores a 1x1 struct with 4 fields using Go. I haven't found anything comparable to Python's SciPy which has a "loadmat" function. What is the best way to read .mat files in Go?

like image 608
Adam Soffer Avatar asked Sep 06 '25 18:09

Adam Soffer


2 Answers

You may have to write your own Go package. MathWorks suggests that you interface with their MATLAB MAT-file C API. To do that in Go, use cgo.

References:

MATLAB MAT-File Format - MathWorks

Command cgo

C? Go? Cgo!

like image 188
peterSO Avatar answered Sep 08 '25 11:09

peterSO


No, there doesn't seem to be any project for reading MalLab files in pure Go (in CGo, see PeterSO's answer):

  • go-search doesn't list any relevant project
  • GitHub doesn't have any either.
  • the Libraries list doesn't include any

And, there were performance consideration as well, mentioned in "Go matrix library".
The discussion was more about calling go from Matlab.

like image 45
VonC Avatar answered Sep 08 '25 11:09

VonC