Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Save matfile to RAM instead of to disk
Replies: 3   Last Post: Apr 7, 2014 3:45 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Yair Altman

Posts: 1,352
Registered: 3/19/07
Re: Save matfile to RAM instead of to disk
Posted: Apr 4, 2014 10:24 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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 c-code. 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/serializing-deserializing-matlab-data
* http://undocumentedmatlab.com/blog/improving-save-performance
* http://undocumentedmatlab.com/blog/improving-fwrite-performance

Yair Altman
http://UndocumentedMatlab.com




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.