How to pass a “.mat” file as an argument of user defined function?
조회 수: 2 (최근 30일)
이전 댓글 표시
Please write demo code.
댓글 수: 0
채택된 답변
Walter Roberson
2016년 1월 31일
function listvars(matfilename)
if ~ischar(matfilename) || ~exist(matfilename,'file')
error('argument must be the name of an existing file');
end
try
datastruct = load(matfilename);
catch
error('Failed in loading from file, might not be real .mat file');
end
fn = fieldnames(datastruct);
if isempty(fn)
fprintf('File loaded but it had no variables stored in it\n');
else
nv = length(fn);
fprintf('File "%s" contains the following %d variable(s)\n', matfilename, nv);
for K = 1 : nv
thisvarname = fn{K};
thiscontent = datastruct.(thisvarname);
fprintf('variable "%s", class "%s"\n', thisvarname, class(thiscontent));
end
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Scope Variables and Generate Names에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!