Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: Save matfile to RAM instead of to disk
Posted:
Apr 4, 2014 10:24 AM


"Jesper Holm" wrote in message <lhmbel$fn$1@newscl01ah.mathworks.com>... > I'm trying to store _any_ type of Matlab variable to a MySQL database (blob data). My question is probably best explained with an example. In the following the 'mvar' is any type of matlab variable. I now do something like this: > > save 'myfile.mat' mvar; % Save var as matfile > h = fopen('myfile.mat','rb'); % Open file for binary reading > rawdata = uint8(fread(h)); % Read contents > fclose(h); % Close file > delete('myfile.mat'); % Delete file again > > I can then store "rawdata" in my database. I'm therefore basically saving the matfile in the database. The procedure can be "reversed" by using a similar appoach (fwrite+load). The solution works, but I was hoping that I could do some kind of magic to avoid the actual disk write/read due to performance issues. > > Any suggestions? > > I should probably mention that we today have a proprietary MEX file that will basically convert a matlab variable to an array of bytes. This involves recursive parsing of the matlab var type in order to handle cell arrays, structs etc. Its a few thousands lines of plain ccode. It works, but it would be so much easier to use the 5 lines of code above instead of going through 2000+ lines of MEX code. > > Any ideas are appreciated. > > Regards, > Jesper
I think you may find the following articles useful: * http://undocumentedmatlab.com/blog/serializingdeserializingmatlabdata * http://undocumentedmatlab.com/blog/improvingsaveperformance * http://undocumentedmatlab.com/blog/improvingfwriteperformance
Yair Altman http://UndocumentedMatlab.com



