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!