Why does it seems like the storage format differs even though the parameters sent to the function save are the same?
Show older comments
I am writing a c# application and want to read mat-files created with Matlab. The data that I want to read in the mat-file is a matlab table. The file format is version 5 according to the header. I have been using the NuGet package MatFileHandler version 1.3.0 (I have also tried the latest beta version 1.4) but I cant read and parse the file properly. It seems that there are different file-format of version 5 eventhough it shouldn't be. Below you'll find a short raw text from the mat-file that can't be parsed. When I have opened a mat-file created in Matlab 2024b instead, the header looks almost the same but in this case the file can be opened and parsed with MatFileHandler. Can someone help me with this issue?
MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Thu Sep 3 15:05:17 2026 ’˛¡å@1V .IL I“|@Ïŧè™è gõ¡PæÑyó IÑA|◊√@Ügì4±ÖFÏIq—Cë‚Aoe•¡⁄4lÇ’õè·›ª¯} Ô>BΩ9€LímàfiÖ·œ◊gfwñiLD«—ƒô¨>ï´'^±æ¬âØdflOÍbl}Ã:õzØ£æRπÏbJr∆ßóW’9‰ús$˘™f∞Àµ~»:[,ìk£≥,1”©‘ø˜ö˙Êæ“[}ÿ¸76øΩ˚IÌÁ{≤0¨9Οû¡⁄≤n86e¨ô.4ÈÙëÚ¬,“;JgãUN©Yor‚O™W €{mr‚Oi3≥Œr*ÙÌ2°ÆÂ∑¸†#GIØ™#Ê.ØÂ€s"Í>#jÂŒù’\mü°Øj‹ˇÑç˜ÂwÙGü6˛‡4;‹n>΢ æ{«˜ÎI˝;ˇŒwÁi◊K1⁄{´Ç Ç Ç Ç Ç Ç Ç ¯O˘ˇˇÏ≈±
†∆ˇèÓ‡&∞ê´ÿ∂m€∂m€∂m€∂ÌŸˇˇÏ≈±
†∆ˇèÓ‡&∞ê´ÿ∂m€∂m€∂m€∂ÌŸˇˇÏ≈±
†∆ˇèÓ‡&∞ê´ÿ∂m€∂m€∂m€∂ÌŸˇˇÏ≈±
†∆ˇèÓ‡&∞ê´ÿ∂m€∂m€∂m€∂ÌŸˇˇÏ≈±
2 Comments
dpb
on 4 Sep 2026 at 11:02
That would seem to be an issue with the NuGet package, not MATLAB and your best chance there would be finding a support group for it.
Have you tried to see if the external package will handle a regular array ok and it may be that it doesn't handle the table correctly is the issue? That might give you a workarounc solution if were to be so.
Fredrik
on 4 Sep 2026 at 11:07
Answers (1)
Actually, the "MATLAB 5.0" text header is a remnant of the past and isn't indicative of the version of the .mat file. Either -v6 or -v7 will contain the same first header text and date so it's not possible from that alone to know.
For MATLAB 5.0, look at Byte 128. If it's 0x78, it's a compressed -v7 file; if it's a low integer, it's an uncompressed -v6 file.
Regarding MatFileHandler: If the file contains a table, make sure you are utilizing the TableAdapter class to extract your columns rather than casting it directly. The library only returns the pieces of the table structure (number of rows and variables, variable and row names, and a big blob of all the data. One would have to reconstruct a table from the pieces; I don't know that C# actually natively supports an equivalent data structure?
T=array2table(randn(5))
save T6 T -v6
whos -file T6
save T7 T -v7
whos -file T7
save T73 T -v7.3
whos -file T73
d=dir('T*.mat');
!ls -lv T*.mat
cellfun(@(f)dbtype(f,'1:1'),{d.name},'uni',0)
NOTA BENE the file sizes are all different between the versions even though the actual content of the file is the same. Particularly note the difference between T6.mat and T7.mat, both of which start with the "MATLAB 5.0" string. The -v7 flag introduces the compression so the file size is quite a lot smaller whereas -v7.3 is the HDF5 format instead of the proprietary binary and the size explodes for small files.
However, I think the mystery of the question in the subject line is clear -- the .mat file format can and will be different depending upon which version switch value was used in creating it but the text .mat file preamble will still look the same; the differences are in the rest of the file structure and which version it is has to be inferred from some other key data, not the text.
Would have to know how the .mat file you're trying to read was created first in order to be able to tell anything more about what the actual root cause is.
Can MATLAB read it successfully? Or attach a sample here to test...
Categories
Find more on Workspace Variables and MAT Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!