Creating a function that gives the size and name of the variables in the mat-file
2 次查看(过去 30 天)
显示 更早的评论
Hi, I am trying to write a function that gives the size and name of the variables in the mat-file
I have this:
S = whos('-file','workspace313.mat')
% lists in alphabetical order the names, sizes, and types of all variables in the currently active workspace.
for k = 1:length(S)
disp([S(k).name, mat2str(S(k).size)]
How do I go on?
0 个评论
回答(1 个)
Image Analyst
2021-5-9
Try this:
d = dir('*.mat'); % Get a list of all .mat files in the current folder.
for k = 1 : length(d)
s = load(d(k).name) % Load it.
names = sort(fieldnames(s)); % Get fieldnames and sort them.
for k2 = 1 : length(names)
fprintf(' File "%s" has a field called %s.\n', d(k).name, names{k2});
end
end
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!