Loading multiple mat files using for loop
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello,
I would like to load multiple mat files in a particular folder. Right now i have 8 matfiles so i have written the code as below.
for k=1:8
S = load(sprintf('M%d.mat',k));
I donot to limit the number of files in code. Is there a way to find the matfiles in a folder and load all the mat files present in the folder.
댓글 수: 1
KSSV
2020년 11월 12일
This question discussed to death in mathworks........a simple google will give you tonns of links.
채택된 답변
Ameer Hamza
2020년 11월 12일
편집: Ameer Hamza
2020년 11월 12일
You can use dir() command to iterate over all the .mat files. For example
files = dir('*.mat');
for i = 1:numel(files)
S = load(files(i).name)
end
댓글 수: 0
추가 답변 (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!