how can we create database with .mat files ?

hello
i have .mat files
its contain heart beat
i want to add it to database and then link it to matlab
how i can add these type of file to database ?
I've attached here one of them here

4 Comments

per isakson
per isakson on 22 Apr 2019
Edited: per isakson on 22 Apr 2019
A month ago you posted a question that is very simialr to this one.
The file s0010_rem.mat contains a <15x10000 double> matrix. Your previous question indicates that you have many such mat-files.
My questions:
  1. Is it worth the trouble for you to transfer those matrices to an sql-database? (You don't want to store the mat-files themselfs in the database.)
  2. Are you comfortable working with sql-databases?
  3. What do you plan to do with this data?
  4. Over how long a period of time?
And finally, give some examples of requests that you want to make to the sql-database.
No, they have repeatedly indicated that they want to store the .mat files in the database, that their teacher has instructed them to do this.
It would make a heck of a lot more sense to store the content of the files in the database, but this is apparently not an option: they specifically want to use a BLOB or MEMO field or LONGINTEGER or whatever is necessary to store the bytes of the .mat file itself.
about your questions
Is it worth the trouble for you to transfer those matrices to an sql-database? (You don't want to store the mat-files themselfs in the database.)
the goal is to store .mat fies somewere , so we can search , view , insert , delete without them beaing in "current folder " matlab
Are you comfortable working with sql-databases?
yes not bad .. but storing .mat files its a new thng for me
What do you plan to do with this data? + Over how long a period of time?
it is a project , my teacher asked me to do
And finally, give some examples of requests that you want to make to the sql-database.
like I said search by name , insert new file , delete , view the content of the specified file
per isakson
per isakson on 23 Apr 2019
Edited: per isakson on 23 Apr 2019
Rahaf mutlaq, My questions are not relevant because I missed the context. Thank you for the answers.

Sign in to comment.

Answers (1)

Yes, it is possible. It is, however, of low value to do so.
.mat files are just files, so they can be read in as arrays of uint8, and those arrays of uint8 can be stored as blobs in a database.
However, all you can do with those blobs is ask about things like the length of the blob, or retrieve the blob in case you wanted to do something like compress the blob as part of a corpus of tests on how well various compression routines do.
To go beyond that, to examine the contents of the .mat that you had stored, you would need information about the detailed binary structure of .mat files. That is documented for MAT5.0 format, but is not completely documented for MAT7.0 files. For MAT7.3 files, all that is documented is that it is a modified HDF5 format.
It is possible to retrieve a blob from the database, write it out to a temporary file, and then use the usual facilities such as load() to retrieve information from the temporary file that was saved from the blob. Many people would suggest that if you were going to do that, then you might as well just store the original files.
Some various recommendations on what you have to tell Microsoft Access in order to store BLOB:

13 Comments

thanks for the answers , I really Appreciate it
but how i can store them as blobs in a database.?
what i want only display the file after i search by its name , thats all
about your question .. my teacher told to do it like this.. so i have to , maybe it's not efficient or I make it harder by doing it like this , but this is what she want :)
To store as blobs, have a look at https://www.mathworks.com/matlabcentral/answers/314634-how-can-i-create-a-new-table-in-a-microsoft-access-database-and-import-data-to-it-using-matlab#answer_246245 and enhance it to support one of the blob underlying types suggested by the three sources I linked to above.
You might have to create the Access database first before you can insert a table; see https://www.mathworks.com/help/database/ug/microsoft-access-odbc-windows.html
You cannot display a .mat file, except as something like a hexadecimal dump.
You could search your database for the file name and confirm whether you had ever heard of it or not, but for that purpose all you need to store is the names.
sorry but its not clear to me :(
how can i store . mat as blob in database ( steps ) ?
shuld i use access or sql ?
after i store it can i retrive it & view it if i search by its name in matlab .. or its impssible ?
I do not have access to Access to test with. I am not sure at the moment whether I have access to Sql.
I have read that since Access 2013 that Memo fields are known as LongText fields.
After you retrieve the mat file stored as a blob you would need to to analyze the binary data to extract the information encoded in it, which is a nuisance and error prone. There are a couple of File Exchange contributions for analyzing the structure of MAT files for diagnostic purposes that you could adapt to extract the data. I really do not recommend this.
Storing MAT files in a database for this purpose is a poor choice and if you have been assigned this task then have the person who assigned it to you contact me and I will convince them to change the requirements. It is a requirement that adds a lot of extra work for no good reason.
... But first I would recommend that you read the assignment very carefully, because there would only be a small number of words different between requiring that MAT files be stored, versus something that would be very much more reasonable.
Rahaf mutlaq
Rahaf mutlaq on 20 Apr 2019
Edited: per isakson on 23 Apr 2019
ok, can you teach me the other best way to do this task ?
what i need :
1- storing mat files in "whereever" on pc
2- search by its name to view content of the file
(i have the code to view the conent of my . mat file but where i use it in my whole code )
3- insert or delete files from the place that is i save these files
Thank you in advance
Store the files in a directory. Use dir() to find the names you have available. When asked to view a particular one expand from the bare name to the full path to the file and load() the content of the file.
just to be clear
you answre on my previuse question :
What is the point in using a database for that? You could just keep a cell array of character vectors, and use ismember() to verify that the query is in the list of known names, and then load() the data from the file. If the same data tends to be loaded multiple times, you could use a containers.Map to cache the values.
and here you suggest me to use dir()
whats the deffrence between them ? i don't want my files to be in " current folder "
is that way makes me load it and view it ? and insert other files with them with no necessary them to be in " current folder"
databasedir = 'C:\Users\Rahaf\EE208\assignment7\databasedir';
dinfo = dir( fullfile(databasedir, '*.mat') );
filenames = {dinfo.name};
[, basenames] = cellfun(@fileparts, filenames, 'uniform', 0);
fullnames = fullfile(databasedir, filenames);
%assuming handles.choose_file is uicontrol listbox or popup
set(handles.choose_file, 'String', basenames, 'UserData', fullnames);
function choose_file_Callback(hObject, event, handles)
choice = get(hObject, 'Value');
if isempty(choice) || choice == 0
return
end
fullnames = get(hObject, 'UserData');
choosen_file = fullnames{choice};
datastruct = load(chosen_file);
data = datastruct.NameOfVariableYouStoredDataInto;
ax = handles.axes_for_plotting_data;
plot(ax, data)
xlabel(ax, 'time')
ylabel(ax, 'amplitude')
legend(ax, {'myofacial', 'left rib 7', 'right glutimus 3'});
its not working :(
i chage the databasedir to the directory of folder that contain my .mat files
' C:\Users\Rahaf mutlaq\Documents\data base[7890]\data base'
i change every (choose_file_Callback) to ( popupmenu1_Callback)
and i paste the rest of code in new script .. but i got error :
Error: File: C:\Users\Rahaf mutlaq\Documents\MATLAB\data base[7890]\Untitled2.m Line: 16
Assignment to popupmenu1_Callback not supported. Variable has the same name as a local function.
I would need to see your Untitled2.m
Note: this code using the handles structure is intended to be used with a GUIDE produced application.
databasedir = 'C:\Users\Rahaf mutlaq\Documents\data base[7890]\data base';
dinfo = dir( fullfile(databasedir, '*.mat ') );
filenames = {dinfo.name};
[ basenames] = cellfun(@fileparts, filenames, 'uniform', 0 );
fullnames = fullfile(databasedir, filenames);
%assuming handles.choose_file is uicontrol listbox or popup
set(handles.popupmenu1_Callback, 'String', basenames, 'UserData', fullnames);
function popupmenu1_Callback(hObject, event, handles )
choice = get(hObject, 'Value ');
if isempty(choice) || choice == 0
return
end
fullnames = get(hObject, 'UserData ');
popupmenu1_Callback = fullnames{choice };
datastruct = load(chosen_file );
data = datastruct.NameOfVariableYouStoredDataInto ;
ax = handles.axes_for_plotting_data ;
plot(ax, data )
xlabel(ax, 'time ')
ylabel(ax, 'amplitude ')
legend(ax, {'myofacial', 'left rib 7', 'right glutimus 3 '});
end
You changed
chosen_file = fullnames{choice};
into
popumpmenu1_Callback = fullnames{choice };
which you should not have done: it should be left as chosen_file
Also, you should not set(handles.popupmenu1_Callback, etc), you should set(handles.popupmenu1, etc)
Note: for this code to execute, something will need to have set handles.popupmenu1 to the handle of a uicontrol style listbox or style popup.
For the callback to work, something will need to have set handles.popupmenu1 'Callback' property to invoke popmenu1_Callback passing in the current handles structure as the third parameter; also, handles.axes_for_plotting_data would have to have been set to an axes handle.
Furthermore, the reference to datastruct.NameOfVariableYouStoredDataInto needs to be adjusted to use the name of the variable that the data is stored in, inside your .mat file.
If you were to create a GUI using GUIDE, then the handles structure and callback property would be set up properly as long as you had given the listbox the tag 'popupmenu1' and you had created an axes that you gave the tag 'axes_for_plotting_data' to.
In practice, if you were to create a GUI using GUIDE, then the *_Callback functions would not terminate with an "end" statement like you have here. You need that "end" if you have that function inside a script, but in practice GUIDE GUIs generate code in function files, not in scripts.
Value of a pop-up menu or listbox is the number of the entry that the user had selected. If the String property was a cell array of three character vectors, and the user selected the second of them, then the Value property would be set to 2. It is not the content of the string that was selected, but you can retrieve the String property and index that at the Value property to get the content of what was selected.
For readability I constructed the popup to have only the base filenames such as 's0010_rem', but for each of those, we need to know the complete filename with directory. You could mnake the complete file name part of what was displayed to the user, but that is generally a waste of space and harder to read. So instead we store the complete names in the UserData property of the uicontrol. The callback retrieves the Value (index number) and we use that to index into the list of complete file names we stored in the UserData property in order to find the complete name of the file to read.

Sign in to comment.

Tags

Asked:

on 18 Apr 2019

Commented:

on 25 Apr 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!