MATLAB Answers

0

how can we create database with .mat files ?

Asked by Rahaf mutlaq on 18 Apr 2019
Latest activity Commented on by Walter Roberson
on 25 Apr 2019
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

Show 1 older comment
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
Rahaf mutlaq, My questions are not relevant because I missed the context. Thank you for the answers.

Sign in to comment.

Tags

1 Answer

Answer by Walter Roberson
on 19 Apr 2019

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

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.