Storing a .mat file in mysql database
조회 수: 22 (최근 30일)
이전 댓글 표시
Hello again, I have a database in which i am storing certians bits of information, however i would like to store the whole .mat file related to this data.Mainly for the purpose if further analysis needs to be preformed on the dataset at a later point.
I have seen some research journals where people have done this and was hoping if someone could point me in the right direction please.
FYI running matlab 7.6.0(R2008a) and query builder is not working for me :(
댓글 수: 0
채택된 답변
Darik
2013년 8월 8일
If you absolutely have to do this, you could create a BLOB column in your database table, then in matlab use the fread function to grab the mat file as raw binary data, and then just insert that into the database. To get the data back out, you would then just fwrite the binary data to disk, and use the load function to read it into matlab.
The huge downside of this whole plan is of course the fact that you won't be able to query in any of the data in the matfile, which is usually the whole reason for storing stuff in a relational database in the first place.
댓글 수: 0
추가 답변 (2개)
Shashank Prasanna
2013년 8월 6일
Since MATLAB supports so many different types of data, you will have to load it into MATLAB first before committing it into a database.
You can start by going through some examples in the Database Toolbox:
Take a look at some of the full example workflows to get an idea of how to insert the data into a table.
댓글 수: 2
Shashank Prasanna
2013년 8월 8일
MAT file is very generic data container therefore I cannot answer your question with an Yes or No. It depends on what data you have within your mat file as I already mentioned.
You can simply write a function or script once to load the matfile and write the data into the specified database. And subsequently all you need to do is call that function again. Otherwise please clarify exactly what your workflow is.
Simon
2023년 5월 13일
In my own experience I have tried three different approaches to store tables in MySQL. I also use Workbench (UI for MySQL commands) for fine-tuning variable types and quick selection and visual inspection of data.
I would suggest you to restructurd your .mat data into tables. Saving tables to MySQL (and other databases) is simpler.
approach I.) When the table has less than 19,000 rows, sqlwrite(conn, tablename, tabledata). For new rows of data, sqlwrite( ) will automatically append to the existing MySQL table.
approach II.) It seems that MySQL has problems with inserting many rows at one time. So when my codes would generate a very tall table, I would run the for-looop to get that talll table. And then I run a separate for-loop to sqlwrite( ) the table rows in chunks.
approach III.) I had also tried embeding sqlwrite( ) to save result in each step in a for-loop bypassing the end-result tall table. For example, if you want to convert and merge many files into a huge table, you could do this way:
for file = 1:number of files
datarows = convert the file( );
make the data rows into a table T.
sqlwrite(conn, 'SQLtablename', T)
end
------
For the moment, I use approach II, because it allows me to use parfor, which is much faster:
parfor i=1:number of files
datarows ....
T = vertcat(datarows) made into a table
end
Next, I would run a separate for-loop for saving to sql.
for row=1:rows
got cor = chunks of rows
sqlwrite(conn, 'SQLtablename', cor)
end
---------
Those are just my personal experiences learned by strugglings with buntch of sql stuff. Hope this might be useful for you.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Database Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!