Creating a function that gives the size and name of the variables in the mat-file

1 Ansicht (letzte 30 Tage)
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?

Antworten (1)

Image Analyst
Image Analyst am 9 Mai 2021
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

Kategorien

Mehr zu Workspace Variables and MAT-Files finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by