how to convert .mat file to .m file in matlab R2019a version
58 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
how to convert .mat file to .m file in matlab R2019a version
1 Commento
Walter Roberson
il 8 Lug 2019
This is not possible in the general case. It is, however, easy in some cases, especially if the .mat contains a single variable that is a numeric vector or 2D array.
Risposte (2)
Stephan
il 8 Lug 2019
You can not convert *.mat to *.m files. The *.mat format saves variables from workspace and the *.m file format saves Matlab code. So there is no way to convert it into each other. It are different formats for different use.
0 Commenti
Cloud
il 7 Ott 2022
When I directly open a MAT file in MatLab, the software generated this snippet automatically.
function import_mat_file(fileToRead1)
%IMPORTFILE(FILETOREAD1)
% Imports data from the specified file
% FILETOREAD1: file to read
% Auto-generated by MATLAB on 06-Oct-2022 18:07:48
% Import the file
newData1 = load('-mat', fileToRead1);
% Create new variables in the base workspace from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
assignin('base', vars{i}, newData1.(vars{i}));
end
You may add function to save extract variables to M file.
My runtime environment:
OS: Windows 10
MatLab: R2022a
6 Commenti
Walter Roberson
il 7 Ott 2022
str = 'αφγα'
bytes = unicode2native(str)
whos bytes
Notice that bytes here is numeric but not double precision.
Likewise, technically str is numeric but not double precision (character vectors are uint16 internally)
vars{i}, newData1.(vars{i}) key and value format,
If you need to represent a cell array and a struct, then those would not be numeric.
When I open the MAT file in MatLab, it looks like bit for bit accuracy.
Yes, .mat files store exact bits. The question I had was whether the .m file that is generated from the .mat needs to exactly reproduce the data from the .mat file, or whether losing the last bit of double precision numbers would be acceptable ?
Cloud
il 7 Ott 2022
@Walter Roberson Thanks for sharing details including web link:
I haven't tried the function.
Whether losing the last bit of double precision numbers would be acceptable ?
I think it depends on application. For me double precision is good enough.
Vedere anche
Categorie
Scopri di più su Workspace Variables and MAT-Files in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!