Why does it seems like the storage format differs even though the parameters sent to the function save are the same?

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

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.
Thank you for your reply. I havn't tried to parse other datatypes than tables. The strange thing is that the resulting mat-file (stored från 2024b end 2025b) differ in how they look, eventhough the data is stored the same way and in version 5. We will see if we can store the data as a matrix instead.
Fredrik

Sign in to comment.

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))
T = 5×5 table
Var1 Var2 Var3 Var4 Var5 _______ ________ ________ ________ _________ 2.0643 0.078716 0.71319 -0.72225 0.036187 -1.2863 -1.8013 -0.33224 -0.17794 -0.17678 -1.8943 -0.95997 0.56011 0.077872 -0.82779 0.97036 0.068858 1.4356 -0.03837 -0.056107 -1.0574 0.63983 1.2593 -1.8681 0.64553
save T6 T -v6
whos -file T6
Name Size Bytes Class Attributes T 5x5 2055 table
save T7 T -v7
whos -file T7
Name Size Bytes Class Attributes T 5x5 2055 table
save T73 T -v7.3
whos -file T73
Name Size Bytes Class Attributes T 5x5 2055 table
d=dir('T*.mat');
!ls -lv T*.mat
-rw-r--r-- 1 matlab matlabgroup 4464 Sep 6 15:36 T6.mat -rw-r--r-- 1 matlab matlabgroup 1120 Sep 6 15:36 T7.mat -rw-r--r-- 1 matlab matlabgroup 29600 Sep 6 15:36 T73.mat
cellfun(@(f)dbtype(f,'1:1'),{d.name},'uni',0)
1 MATLAB 5.0 MAT-file, Platform: GLNXA64, Created on: Sun Sep 6 15:36:22 2026 □□□□□□□□□IM□□□□□□□□□□□□□□□□□□□□□□□□□□T□□□□□□□MCOS□□□□□□□□table□□□□□□□H□□□□□□□□□ 1 MATLAB 5.0 MAT-file, Platform: GLNXA64, Created on: Sun Sep 6 15:36:22 2026 Ñ□□□□□□□□□IM□□□□I□□□x□ãc``h□b6 æ□bA`□Â□0ÍÂàëì□d³□qIbRN*□æ□b□$}¼P}¬P>□X/□3@ù□□æ]&$9□□□à□□Ð□□□□□□□□x□ãc``Ð□```□Ò□@ÌÉ□□¬P>#□ÿà□Ð À□å30zú□ø|@□Á□ÐÏ□E?□CÄYÀr□P5¾ÎþÁ0s□□Ì□□ªg□Ó,`µ >/□»eæ¤□□%□□¤□ÅÇCõ_àCèGØ□áó ¹□¤>□□·¿-□QÕ3AÅX ò @Ü□Å□@n□Ê)@±□□§$□$2ä¥dæ□3ä□å□□3□□¼ÄÜT ·,±¨□□H@¸□Eù□Å□%□I9©□8□□. $À□□□,ÆÎ□é□□□□J□ÄX□Ä`ñ□□cc@Ä□Ì,6□î1@r□□□ÍÁ□;□`v ÇS□□B=□□z□Z□zP<j□±□Üb□ÃÍ□□ÿ6□□Ø?åËþ□□' □ùÿÛß□□□iÀûÞÞâFp¤Ùë□ûÉ5_Z]#b»Ú□{±□□¿~\ü³¿Ðä¿¥à□wûù¦□O_»`£}Õ®□7Ê+□Ø□kþã0=«ªKÏì#□?□,s¾ºÿ¶Ù«¸□7□í×óG+Zÿøfÿ□□÷"□Ú□²Í÷^Ç'¶IæùþCöÿ 1 MATLAB 7.3 MAT-file, Platform: GLNXA64, Created on: Sun Sep 6 15:36:22 2026 HDF5 schema 1.00 . □□□□□□□□□□IM□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□HDF
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...

Products

Release

R2025b

Asked:

on 4 Sep 2026 at 6:41

Edited:

dpb
on 6 Sep 2026 at 15:37

Community Treasure Hunt

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

Start Hunting!