Can not read MAT file in another language

I have two MAT files. I can open A but can not open B in Julia.
When I used the command “@show(File)”. I got the below for File A:
F1 = MAT.MAT_HDF5.MatlabHDF5File(HDF5.File: (read-only) /Volumes/A.mat, true, false, 1108, false)
but the below for File B:
F2 = MAT.MAT_v5.Matlabv5File(IOStream(<file /Volumes/B.mat>), false, undef)
File A was created by someone I do not know, and File B was created by myself using the command below:
save(File_W, Variable1, Variable2);
I can open File B in Matlab easily. What is wrong with my file B? Is that because it is a special type of MAT file, i.e., HDF5? How do I create HDF5 flavored MAT files to make it more versatile? Thanks.

 Respuesta aceptada

My guess is Julia can read a .mat file created for an earlier release of MATLAB. Looking at the help for save, you can specify a different save format, able to be read into an earlier MATLAB release.
The default is "-v7" as you can see from the help. But you might try "-v6", or "-v4".
help save
save - Save variables from workspace to file This MATLAB function saves all variables from the current workspace in a binary MATLAB file (MAT-file) named filename. Syntax save(filename) save(filename,variables) save(filename,variables,fmt) save(filename,variables,version) save(filename,variables,version,"-nocompression") save(filename,variables,"-append") save(filename,variables,"-append","-nocompression") save filename Input Arguments filename - Name of file "matlab.mat" (default) | string scalar | character vector variables - Names of variables to save string scalar | character vector fmt - File format "-mat" (default) | "-ascii" | "-ascii","-tabs" | "-ascii","-double" | "-ascii","-double","-tabs" version - MAT-file version "-v7" (default) | "-v7.3" | "-v6" | "-v4" Examples openExample('matlab/SaveAllWorkspaceVariablesToMATFileExample') openExample('matlab/SaveSpecificVariablestoMATFileExample') openExample('matlab/SaveDataToASCIIFileExample') openExample('matlab/SaveStructureFieldsasIndividualVariablesExample') openExample('matlab/SaveVariablesToVersion73MATFileExample') openExample('matlab/SaveVariablesToVersion7p3MATFileWithoutCompressionExample') openExample('matlab/AppendVariableToMATFileExample') openExample('matlab/AppendVariableToMATFileWithoutCompressionExample') openExample('matlab/SaveOnlyVariablesThatAlreadyExistInFileExample') See also clear, hgsave, load, matfile, regexp, saveas, whos Introduced in MATLAB before R2006a Documentation for save doc save Other uses of save cgproject/save COM.com/save COM/save imaq/save instrument/save matlab.diagram.ClassViewer/save mdevproject/save rmidata/save sim3d.Actor/save sim3d.World/save Simulink.Bus/save Simulink.CodeImporter/save Simulink.dialog.MaskPartReference/save Simulink.ModelWorkspace/save Simulink.ScenarioSimulation/save Simulink.sdi/save slcoverage.Filter/save slreq.LinkSet/save slreq.ReqSet/save

3 comentarios

The opposite -- Julia can open the HDF5 based -v7.3 file but not the -v7 file.
So try
save(File_W, '-v7.3', Variable1, Variable2);
John D'Errico
John D'Errico el 26 de Jun. de 2025
I was pretty sure it was a choice of save version. It just went the other way.
Leon
Leon el 26 de Jun. de 2025
'-v7.3' works.
Many thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2024b

Etiquetas

Preguntada:

el 25 de Jun. de 2025

Comentada:

el 26 de Jun. de 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by