How Can I read the contents of .mat files ?
306 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
更多回答(3 个)
Star Strider
2014-10-10
You can check the contents of .mat files and load specific data from them with the matfile function.
4 个评论
Walter Roberson
2025-9-19
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
Hunt3r5o4
2025-9-18
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!