From octave-maintainers-request at bevo dot che dot wisc dot edu Sun Feb 20 17:42:41 2000 Subject: version 5 MATLAB binary format From: "James R. Van Zandt" To: octave-maintainers at bevo dot che dot wisc dot edu Date: Sun, 20 Feb 2000 18:32:39 -0500 (EST) Octave users - I am trying to work out the format of binary .mat files generated by MATLAB of version 5 and later. I think I understand the features I'm interested in, except for things that may vary based on architecture or version: endianness, padding, and of course labeling. I think the attached script exercises all the necessary features. I would appreciate it if users with access to MATLAB would run the script and mail me the resulting matfile.tar.gz file. Thanks in advance! - Jim Van Zandt #!/bin/sh -c uname -a >matfile.log date >>matfile.log matlab -q >>matfile.log < hex 33 33 33 33 33 33 f3 3f (IEEE floating point, little endian arch) a=1.2; save a1 a al=1.2; save a2 al alp=1.2; save a3 alp alph=1.2; save a4 alph alpha=1.2; save a5 alpha % bytes and integers digits1=7; digits2=77; digits3=777; digits4=7777; digits5=77777; digits6=777777; imaginarydouble=1.2i; complexdouble=(290+306i)/255; imaginaryint=70001i; complexint=70002+70003i; imaginaryshort=701i; complexshort=702+703i; imaginarybyte=5i; complexbyte=6+7i; save a6 digits1 digits2 digits3 digits4 digits5 digits6 ... imaginarydouble complexdouble ... imaginaryint complexint ... imaginaryshort complexshort ... imaginarybyte complexbyte; m2g0=-256^4/2-1; m2g=-256^4/2; m2g1=-256^4/2+1; m2g2=-256^4/2+2; p2g0=256^4/2+1; p2g=256^4/2; p2g1=256^4/2-1; p2g2=256^4/2-2; m32769=-32769; m32768=-32768; m32767=-32767; m32766=-32766; p32769=32769; p32768=32768; p32767=32767; p32766=32766; m512=-512; m511=-511; m255=-255; m254=-254; m128=-128; m127=-127; p512=512; p511=511; p255=255; p254=254; p128=128; p127=127; save a7 m2g0 m2g m2g1 m2g2 p2g0 p2g p2g1 p2g2 ... m32769 m32768 m32767 m32766 p32769 p32768 p32767 p32766 ... m512 m511 m255 m254 m128 m127 p127 p128 p254 p255 p511 p512; % byte order a100=.5; a101=.5+1/256; a102=.5+1/256/256; a103=.5+1/256/256/256; a104=.5+1/256/256/256/256; a105=.5+1/256/256/256/256/256; a106=.5+1/256/256/256/256/256/256; a107=.5+1/256/256/256/256/256/256/256; save a8 a100 a101 a102 a103 a104 a105 a106 a107; % arrays (these values are easy to pick out of the ASCII part of a dump) array8=[274 290 306 322 338 354 370 386]/255; array7=[274 290 306 322 338 354 370]/255; array6=[274 290 306 322 338 354]/255; array23=[274 290 306;322 338 354]/255; array32=[274 290;306 322;338 354]/255; save b1 array8 array7 array6 array23 array32; bytes=[1 2 3 4 5 6]; bigbytes=[127 128 129 130]; biggerbytes=[254 255 256 257 258]; negbytes=[-1 -2 -3 -4 -5 -6]; shorts=[701 702 703 704 705 706]; negshorts=[-701 -702 -703 -704]; ints=[70001 70002 70003 70004]; negints=[-70001 -70002 -70003 -70004]; complex5=[274+290i 306+322i 338+354i 370+386i 402]/255; complex23=[274+290i 306+322i 338+354i; 370 386i 402i]/255; save b2 bytes bigbytes biggerbytes negbytes ... shorts negshorts ints negints complex5 complex23 % strings string1='a string'; thisvariablenameismorethanthirtytwocharacterslong='a longer string'; string3='a still longer string'; save c1 string1 thisvariablenameismorethanthirtytwocharacterslong string3; % structures epsilon.alpha=274/255; % real save e1 epsilon; epsilon.beta=58/51i; % pure imaginary save e2 epsilon; epsilon.gamma=6/5+322/255i; % complex epsilon.thisvariablenameismorethanthirtytwocharacterslong='a string'; epsilon.epsilon=[1 2 3; 4 5 6]; save e3 epsilon; epsilon.sub.aa=322/255; epsilon.sub.bb=338/255; epsilon.sub.cc=118/85; save e4 epsilon; quit EOF tar -cf matfile.tar matfile.log [abcde][1-9].mat matfile.sh gzip matfile.tar