JimHokanson / adinstruments_sdk_matlab

Implementation of AD Instruments SDK in Matlab - i.e. reads LabChart files
MIT License
26 stars 8 forks source link

How to set matlab version when running adi.convert in matlab? #15

Closed jay-sf closed 3 years ago

jay-sf commented 3 years ago

Hi Jim,

first of all thanks a ton for sharing this code, which already works fantastic!

However, using R.matlab package in R I ran into an issue. The package wants v6 .mat files but your code is generating v7 .mat files. According to the R error message below one should use save -V6 (or probably use an older Matlab version). I looked into your code but since I am not very proficient in Matlab, I don't know where to set the parameter. Maybe you could help?

Cheers

> R.matlab::readMat('foo.mat')
Error in readMat5(con, firstFourBytes = firstFourBytes, maxLength = maxLength) : 
  Reading of MAT v7.3 files is not supported. If possible, save the data in MATLAB using 'save -V6'.
JimHokanson commented 3 years ago

See the latest version. I thought I had implemented partial reading support but I had not. That made this change rather easy. Basically for conversion I read the entire file into memory and then write it once. This works for smaller files but for really large files it would be better to read chunks, write them, then read more. Anyway, since I only write once, it was really easy to change the save flag.

The new code looks like:

options = adi.mat_conversion_options;
options.version = '-v6';
adi.convert(file_path,'conversion_options',options);

Note, v6 doesn't support compression, so the files are rather large. You could try -v7 which may work and also support compression. The default is -v7.3.