how to convert .mat file to .m file in matlab R2019a version
38 views (last 30 days)
Show older comments
how to convert .mat file to .m file in matlab R2019a version
1 Comment
Walter Roberson
on 8 Jul 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.
Answers (2)
Stephan
on 8 Jul 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 Comments
Cloud
on 7 Oct 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 Comments
Cloud
on 7 Oct 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.
See Also
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!