How Can I read the contents of .mat files ?

282 vues (au cours des 30 derniers jours)
farzad
farzad le 10 Oct 2014
Commenté : Walter Roberson le 19 Sep 2025
Hi All
I have an m file and a set of .mat files that are connected to this m file and m file loads their data , I need to know whether I can open and extract all the data of these .mat files and check what they contain
thank you very much

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 10 Oct 2014
data=load('your_file_name')
  1 commentaire
farzad
farzad le 10 Oct 2014
Thanks a lot Azzi

Connectez-vous pour commenter.

Plus de réponses (3)

Star Strider
Star Strider le 10 Oct 2014
You can check the contents of .mat files and load specific data from them with the matfile function.
  4 commentaires
Star Strider
Star Strider le 18 Sep 2025
@Hakan -- My pleasure!
Walter Roberson
Walter Roberson le 19 Sep 2025
There is a limitation, that matfile() cannot be used with -v4 .mat files.
vers = ["v4", "v6", "v7", "v7.3"];
nvers = length(vers);
rng(12345);
data = randi([0 255], 1, 50, 'uint8');
for K = 1 : nvers
v = vers(K);
fname = "data_" + v + ".mat";
save(fname, "data", "-" + v );
try
whos('-file', fname);
catch ME
fprintf('error doing whos for "%s"', fname);
end
try
obj = matfile(fname);
whos(obj);
catch ME
fprintf('error doing matfile for "%s"', fname)
end
end
Warning: Variable 'data' was not saved. For variable of type 'uint8' use MAT-file version 6 or later.
error doing whos for "data_v4.mat"
error doing matfile for "data_v4.mat"
Name Size Bytes Class Attributes data 1x50 50 uint8
Name Size Bytes Class Attributes data 1x50 50 uint8
Name Size Bytes Class Attributes data 1x50 50 uint8
Name Size Bytes Class Attributes data 1x50 50 uint8
Name Size Bytes Class Attributes data 1x50 50 uint8
Name Size Bytes Class Attributes data 1x50 50 uint8

Connectez-vous pour commenter.


Nelson
Nelson le 9 Juin 2022
data=load('fun')

Hunt3r5o4
Hunt3r5o4 le 18 Sep 2025
You can use
matObj = matfile("path");
This gives all the variables within the .mat file.
variable = matObj.variable;
This gives you a specific variable within the .mat file.
disp(variable);
This will display the variable.

Catégories

En savoir plus sur Workspace Variables and MAT Files dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by