how can we create database with .mat files ?
Mostrar comentarios más antiguos
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 comentarios
per isakson
el 22 de Abr. de 2019
Editada: per isakson
el 22 de Abr. de 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:
- 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.)
- Are you comfortable working with sql-databases?
- What do you plan to do with this data?
- Over how long a period of time?
And finally, give some examples of requests that you want to make to the sql-database.
Walter Roberson
el 22 de Abr. de 2019
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.
Rahaf mutlaq
el 22 de Abr. de 2019
per isakson
el 23 de Abr. de 2019
Editada: per isakson
el 23 de Abr. de 2019
Rahaf mutlaq, My questions are not relevant because I missed the context. Thank you for the answers.
Respuestas (1)
Walter Roberson
el 19 de Abr. de 2019
0 votos
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:
... You still haven't answered my question at https://www.mathworks.com/matlabcentral/answers/451967-mat-files-database#comment_695325
13 comentarios
Rahaf mutlaq
el 19 de Abr. de 2019
Walter Roberson
el 19 de Abr. de 2019
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.
Rahaf mutlaq
el 20 de Abr. de 2019
Walter Roberson
el 20 de Abr. de 2019
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
el 20 de Abr. de 2019
Editada: per isakson
el 23 de Abr. de 2019
Walter Roberson
el 20 de Abr. de 2019
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.
Rahaf mutlaq
el 21 de Abr. de 2019
Walter Roberson
el 21 de Abr. de 2019
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'});
Rahaf mutlaq
el 22 de Abr. de 2019
Walter Roberson
el 22 de Abr. de 2019
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.
Rahaf mutlaq
el 22 de Abr. de 2019
Walter Roberson
el 22 de Abr. de 2019
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.
Walter Roberson
el 25 de Abr. de 2019
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.
Categorías
Más información sobre Database Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!